[rspec-users] Calling let(:something) from before blocks?
Christoph Schiessl
chs at proactive.cc
Fri Nov 5 15:12:13 EDT 2010
Hello!
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" }
end
# ...
end
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,
Christoph
PS: I'm using rspec 2.0.1, rails 3.0.1 and ruby 1.8.7.
More information about the rspec-users
mailing list