Failing View Spec, rspec-rails 2.2.1

Hello all.

Just a little frustration moment here and hoping someone can explain to
me
what is going on.

I had a passing view spec using >= rspec-rails2. Then after updating to
2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in
the
rspec book, and I get the same thing. Here is the full source:
https://github.com/matthewcalebsmith/rspec_issue.git

If I switch out the message.stub(:title => “the title”) in “it ‘renders
a
text field for the message title’ do” with assign(:message,
mock_model(“Message”,:title => “the title”).as_new_record), everything
passes. Why does the stub not work anymore?

Using the stub gives this:

  1. messages/new.html.erb renders a text field for the message title
    Failure/Error: form.should have_selector(“input”,
    expected following output to contain a tag:<form accept-charset="UTF-8" action="/messages" class="new_message"

id=“new_message” method=“post”>


Note the
value=“Message_#<RSpec::Core::ExampleGroup::Nested_1:0x0000010312db68>”,
which must be why the test fails. Is this an intentional change on how
stub
or assign works?

Much thanks!

Matt Smith

On Dec 1, 2010, at 11:30 AM, Matt Smith wrote:

Hello all.

Just a little frustration moment here and hoping someone can explain to me what
is going on.

I had a passing view spec using >= rspec-rails2. Then after updating to
2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in the rspec
book, and I get the same thing. Here is the full source:
https://github.com/matthewcalebsmith/rspec_issue.git

The repo appears to be gone. Have you resolved the issue?

I’m running into this issue as well. Surely someone has a solution?
Seems to be Rails 3.0.3.

On Thu, Dec 9, 2010 at 6:43 AM, Sid W. [email protected] wrote:

I’m running into this issue as well. Surely someone has a solution?
Seems to be Rails 3.0.3.

Please be sure to quote relevant parts of the thread to provide
context for people who are reading on phones, etc, that don’t make it
easy to see an entire thread.

Here’s a snip from the original post:

I had a passing view spec using >= rspec-rails2. Then after updating to 2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in the rspec book, and I get the same thing. Here is the full source: https://github.com/matthewcalebsmith/rspec_issue.git

If I switch out the message.stub(:title => “the title”) in “it
‘renders a text field for the message title’ do” with assign(:message,
mock_model(“Message”,:title => “the title”).as_new_record), everything
passes. Why does the stub not work anymore?

Using the stub gives this:

  1. messages/new.html.erb renders a text field for the message title
    Failure/Error: form.should have_selector(“input”,
    expected following output to contain a tag:<form accept-charset="UTF-8" action="/messages"

class=“new_message” id=“new_message” method=“post”>



This is a regression that was introduced by an enhancement in
rspec-mocks-2.2. It has been reported, identified, and fixed, but not
yet released:

I’ll try to get an rspec-rails-2.2.2 release out this weekend with
this fix. In the mean time, you can point your Gemfile to the branch
on github and get the fix right now:

gem “rspec-rails”, :git => “git://github.com/rspec/rspec-rails”,
:branch => “2-2-maintenance”

HTH,
David

David C. wrote in post #967419:

I’ll try to get an rspec-rails-2.2.2 release out this weekend with
this fix. In the mean time, you can point your Gemfile to the branch
on github and get the fix right now:

gem “rspec-rails”, :git => “git://github.com/rspec/rspec-rails”,
:branch => “2-2-maintenance”

You’re an absolute star David. Thanks!

Here is a simple example of the breaking code;

====== CODE ========
describe “payments/new.html.haml” do
let(:payment) do
mock_model(“Payment”).as_new_record.as_null_object
end

before do
assign(:payment, payment)
end

it “renders a form to take payment details” do
render
rendered.should have_selector(“form”,
:method => “post”,
:action => payments_path
) do |form|
form.should have_selector(“input”, :type => “submit”)
end
end

it “renders a text field for the billing name” do
payment.stub(:billing_name => “Mr. Test Pants”)
render
rendered.should have_selector(“form”) do |form|
form.should have_selector(“input”,
:type => “text”,
:name => “payment[billing_name]”,
:value => “Mr. Test Pants”
)
end
end

end

Here is the error;

====== ERROR ========
Failure/Error: form.should have_selector(“input”,
expected following output to contain a tag:



Sid W. wrote in post #967432:

gem ‘rspec-rails’, :git => ‘git://github.com/rspec/rspec-rails’

Missing .git corrected but still no joy.

Sid W. wrote in post #967432:

It appears that the fix you mention is in master not 2-2-maintenance.
Due to RSpec 2.3 dependancies I’ve added the following to my Gemfile

gem ‘rspec’, :git => ‘git://github.com/rspec/rspec.git’
gem ‘rspec-expectations’, :git =>
‘git://github.com/rspec/rspec-expectations.git’
gem ‘rspec-core’, :git => ‘git://github.com/rspec/rspec-core.git’
gem ‘rspec-mocks’, :git => ‘git://github.com/rspec/rspec-mocks.git’
gem ‘rspec-rails’, :git => ‘git://github.com/rspec/rspec-rails’

Unfortunately, the same error persists. :frowning:

So my previous code example works with the master branch gems except it
breaks with the addition of another test block. The following code
breaks with a similar error.

======== CODE ==========

describe “payments/new.html.haml” do
let(:payment) do
mock_model(“Payment”).as_new_record.as_null_object
end

before do
assign(:payment, payment)
end

it “renders a form to take payment details” do
render
rendered.should have_selector(“form”,
:method => “post”,
:action => payments_path
) do |form|
form.should have_selector(“input”, :type => “submit”)
end
end

it “renders a text field for the billing name” do
payment.stub(:billing_name => “Mr. Test Pants”)
render
rendered.should have_selector(“form”) do |form|
form.should have_selector(“input”,
:type => “text”,
:name => “payment[billing_name]”,
:value => “Mr. Test Pants”
)
end
end

it “renders a text field for the first billing street address line” do
payment.stub(:billing_street1 => “Flat 123”)
render
rendered.should have_selector(“form”) do |form|
form.should have_selector(“input”,
:type => ‘text’,
:name => ‘payment[billing_address1]’,
:value => ‘Flat 123’
)
end
end
end

Here is the error.

========ERROR==========
Failure/Error: form.should have_selector(“input”,
expected following output to contain a tag:



David C. wrote in post #967419:

This is a regression that was introduced by an enhancement in
rspec-mocks-2.2. It has been reported, identified, and fixed, but not
yet released:

Issues · rspec/rspec-rails · GitHub

I’ll try to get an rspec-rails-2.2.2 release out this weekend with
this fix. In the mean time, you can point your Gemfile to the branch
on github and get the fix right now:

gem “rspec-rails”, :git => “git://github.com/rspec/rspec-rails”,
:branch => “2-2-maintenance”

HTH,
David

It appears that the fix you mention is in master not 2-2-maintenance.
Due to RSpec 2.3 dependancies I’ve added the following to my Gemfile

gem ‘rspec’, :git => ‘git://github.com/rspec/rspec.git’
gem ‘rspec-expectations’, :git =>
‘git://github.com/rspec/rspec-expectations.git’
gem ‘rspec-core’, :git => ‘git://github.com/rspec/rspec-core.git’
gem ‘rspec-mocks’, :git => ‘git://github.com/rspec/rspec-mocks.git’
gem ‘rspec-rails’, :git => ‘git://github.com/rspec/rspec-rails’

Unfortunately, the same error persists. :frowning:

On Dec 9, 2010, at 8:57 AM, Sid W. wrote:

gem ‘rspec-expectations’, :git =>
‘git://github.com/rspec/rspec-expectations.git’
gem ‘rspec-core’, :git => ‘git://github.com/rspec/rspec-core.git’
gem ‘rspec-mocks’, :git => ‘git://github.com/rspec/rspec-mocks.git’
gem ‘rspec-rails’, :git => ‘git://github.com/rspec/rspec-rails’

Unfortunately, the same error persists. :frowning:

I cherry-picked the commit onto the 2-2-maintenance branch. Please try
again with only rspec-rails coming from git.

Hey David,

You rock. Thanks a million. Got it working right away!

Thanks,

Matt