On Tue, May 12, 2009 at 12:14 PM, mortench <morte...@gmail.com> wrote: > The new rspec beta book and the rspec site mentions that it is > possible to add a hash to "describe" and "it" constructs but very, > very litle information about the particulars. > > What can the options hash be used for and what should it be used for? > > F.x. I have some identical examples that I need to run against a wide > range of different models that have two configuration parameters that > sometimes differ. I am thus thinking of using the has like this in > example groups (tptions which are recoginzed in helpers, macros etc): > > describe XXXX-MODEL, :fixturesRelativeRootDir => > ‘testfixtures’, :serviceDescriptorRelativePath => ‘services/ > RubyHelloExample.service’ > > Does usage of custom options like this make sense rspec-wise ? > > Finally, I did find out myself that I can get the hash from a helper’s > Spec::Runner.configure.config.before(:all) using “self.class”. > However, this does not work inside nested “it” constructs. Any advice ?
You can access the group and example options from within an example: describe "group options hash", :defined_in => :group do it "is available in examples via self.class.options" do self.class.options[:defined_in].should == :group end end describe "example options hash" do it "is available in examples directly", :defined_in => :example do options[:defined_in].should == :example end end HTH, David _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users