[rspec-users] need some advice on the best way to structure testable shared methods
Patrick J. Collins
patrick at collinatorstudios.com
Tue Nov 15 00:59:33 EST 2011
> Use the described class:
>
> shared_examples "a nameable thingie" do |klass|
> describe "#build_name" do
> it "it adds the collection of arguments to the base components and formats them for a form element name attribute" do
> described_class.new(nil,nil).build_name(:lol, :lollerskates, :roflcopter).should == "lol[lollerskates][roflcopter]"
> end
> end
> end
But what happens if the classes do not have the same argument expectations,
such as:
class Foo
include NameBuilder
def initialize(arg1)
...
end
end
class Bar
include NameBuilder
def initialize(arg1, arg2, arg3)
...
end
end
...
In this case, "described_class.new(nil, nil)" is not going to work out very
well.
Patrick J. Collins
http://collinatorstudios.com
More information about the rspec-users
mailing list