Christoph Schiessl
2010-Nov-05 19:12 UTC
[rspec-users] Calling let(:something) from before blocks?
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.
Christoph Schiessl
2010-Nov-05 20:39 UTC
[rspec-users] Calling let(:something) from before blocks?
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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101105/e2e9bcfa/attachment.html>
David Chelimsky
2010-Nov-05 21:47 UTC
[rspec-users] Calling let(:something) from before blocks?
On Nov 5, 2010, at 3:39 PM, Christoph Schiessl wrote:> 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?Not as of yet. Not sure if I''d like to add it or not, but please file a feature request: http://github.com/rspec/rspec-core/issues. Thx, David> > Thx & best regards, > Christoph > > PS: I''m using rspec 2.0.1, rails 3.0.1 and ruby 1.8.7. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101105/932816b9/attachment.html>