Strange issue with the 'its' construct

The ‘its’ construct seems to not be working for me. I have narrowed it
down to a basic example that I think should be working. Note that when I
use a normal ‘it’ block with a subject in it, that works fine.

Any insights would be welcome: sdfsdf · GitHub

Cheers, Tom.

== Below is just a copy of the content of the gist ==

: cat spec/controllers/simple_spec.rb
require File.expand_path(File.dirname(FILE) + ‘/…/spec_helper’)

describe HomeController do
context “looking at an email” do
subject do
mail = TMail::Mail.new
mail.from = “[email protected]
mail
end

# This passes as expected.
it "should have the correct from address" do
  subject.from.should == ['[email protected]']
end

# I don't understand why this fails.
its(:from) { should == ['[email protected]'] }

end
end

: ./script/spec spec/controllers/simple_spec.rb -b
.F

NoMethodError in ‘HomeController looking at an email from should ==
[“[email protected]”]’
undefined method from' for #<HomeController:0x102bd7c40> /my/project/vendor/gems/rspec-1.3.0/lib/spec/example/subject.rb:25:in send’
/my/project/vendor/gems/rspec-1.3.0/lib/spec/example/subject.rb:25:in
subject' /my/project/vendor/gems/rspec-1.3.0/lib/spec/example/subject.rb:91:in should’
./spec/controllers/simple_spec.rb:14:
/my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:40:in
instance_eval' /my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:40:in execute’
/Users/tomtt/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/timeout.rb:53:in
timeout' /my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:37:in execute’
/my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:214:in
run_examples' /my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in each’
/my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in
run_examples' /my/project/vendor/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:103:in run’
/my/project/vendor/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:23:in
run' /my/project/vendor/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in each’
/my/project/vendor/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in
run' /my/project/vendor/gems/rspec-1.3.0/lib/spec/runner/options.rb:152:in run_examples’
/my/project/vendor/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in
`run’
./script/spec:10:

Finished in 0.031435 seconds

2 examples, 1 failure

On May 20, 2010, at 11:49 AM, Tom Ten T. wrote:

: cat spec/controllers/simple_spec.rb

This passes as expected.

it “should have the correct from address” do
subject.from.should == [‘[email protected]’]
end

I don’t understand why this fails.

its(:from) { should == [‘[email protected]’] }
end
end

: ./script/spec spec/controllers/simple_spec.rb -b

Please file a bug at Lighthouse - Beautifully Simple Issue Tracking
if there’s not one already.

Thanks,
David

David C. wrote:

Please file a bug at Lighthouse - Beautifully Simple Issue Tracking
if there’s not one already.

I was unable to find one, so I created this:
https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/998-explicit-subject-block-in-a-controller-spec-returns-the-controller-instead-of-the-subject-defined-in-the-example-group

Another finding is that this only occurs when running the file from
spec/controllers, it’s fine when run from spec/models. Details are on
the ticket.

Thanks, Tom