[rspec-users] Calling let(:something) from before blocks?

Christoph Schiessl chs at proactive.cc
Fri Nov 5 16:39:03 EDT 2010


I find myself repeating the same `let(:something)` statements over and over again in different view examples. Therefore, I wonder if it's possible to define these globally in the spec_helper.rb file. I came up with the following approach:

 # spec/spec_helper.rb
 RSpec.configure do |config|
   # ...
   config.before(:each, :type => :view) do
     let(:something) { "available for **all** view examples" }
   # ...

However, this doesn't work because `let` isn't defined in that context:

 Failure/Error: Unable to find matching line from backtrace
 undefined method `let' for #<RSpec::Core::ExampleGroup::Nested_1:0x105569298>

Some kind of workaround to make this work would be really nice. Is this usage of `let` supported at all?

Thx & best regards,

PS: I'm using rspec 2.0.1, rails 3.0.1 and ruby 1.8.7.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101105/e2e9bcfa/attachment.html>

More information about the rspec-users mailing list