0.0
No commit activity in last 3 years
No release in over 3 years
rspec-with-args attempts to cut out having to explicitly write the subject of your example group when trying to call methods or add arguments to methods. It works by reading the conventional description syntax to determine what the subject is. Then allowing you to explicitly state what variables will be passed in as arguments. Currently it supports initialization, class methods, and instance methods.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

#rspec-with-args-0.0.3

rspec-with-args attempts to cut out having to explicitly write the subject of your example group when trying to call methods or add arguments to methods. It works by reading the conventional description syntax to determine what the subject is. Then allowing you to explicitly state what variables will be passed in as arguments.

Currently it supports initialization, class methods, and instance methods.

##example specs

require 'rspec-with_args'

class Bar
  def foo
    "bar"
  end
end

class Foo < Struct.new(:arg1, :arg2)
  def foo(m_arg1)
    m_arg1 + arg1
  end

  def self.class_method(c_arg1, c_arg2)
    c_arg1 + c_arg2
  end
end

RSpec.configure do |c|
  c.treat_symbols_as_metadata_keys_with_true_values = true
end

describe Bar, :with_args do
  context "instance methods with no args" do
    describe "#foo" do
      it { should eq "bar" }
    end
  end
end

describe Foo, with_args: [:bar, :baz] do
  let(:bar) { "bar" }
  let(:baz) { "baz" }

  context "subject initialization" do
    it { should eq(Foo.new(bar, baz)) }

    context "with changed arguments" do
      let(:bar) { "bee" }
      let(:baz) { "boo" }

      it { should eq(Foo.new(bar, baz)) }
    end
  end

  context "explicitly setting the subject" do
    subject { described_class.new(fuu) }
    let(:fuu) { "fuu" }

    it "overrides with-args default subject" do
      subject.arg1.should eq(fuu)
    end
  end

  context "method arguments" do
    describe "#foo", with_args: [:zoo] do
      let(:zoo) { "zoo" }
      context "has access to initialization arguments" do
        it { should eq(zoo + bar) }
      end

      context "with changed arguments" do
        let(:zoo) { "zuu" }
        let(:bar) { "baar" }

        it { should eq(zoo + bar) }
      end
    end
  end

  context "class method arguments" do
    describe ".class_method", with_args: [:zoo, :bar] do
      let(:zoo) { "zoo" }
      let(:bar) { "bar" }

      it { should eq(zoo + bar) }

      context "with changed arguments" do
        let(:zoo) { "zuu" }
        let(:bar) { "baar" }

        it { should eq(zoo + bar) }
      end
    end
  end
end