[rspec-users] Custom Example Groups
Matt Wynne
matt at mattwynne.net
Sun Apr 19 10:11:25 EDT 2009
On 19 Apr 2009, at 13:58, David Chelimsky wrote:
> Also - you really don't need custom groups for this sort of thing,
> because you can define with_method in a module and extend the
> configuration w/ that module:
>
> module WithMethod
> def with_method(verb)
> subject { send(verb, description_args.first) }
> yield
> end
> end
>
> Spec::Runner.configure {|c| c.extend(WithMethod)}
>
> Cheers,
> David
Or even (if I'm following this correctly) just define it right there
inside your describe block:
describe "custom example group" do
# available in groups
def self.custom_example_group_method
puts "hello from a custom example group class"
end
# available in examples
def custom_example_method
puts "hello from a custom example group instance"
end
custom_example_group_method
it "provides access to instance methods" do
custom_example_method
end
end
Obviously this doesn't give you any re-use yet, but it's usually the
very first step I take before factoring out a module like David's
suggested. I've yet to need to take it as far as the custom example
group class, but I like the concept.
Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
More information about the rspec-users
mailing list