[rspec-users] One error reported recursively if two pages visited by request spec

Mark Berry mcbsystems at gmail.com
Thu Apr 19 15:54:07 UTC 2012


On Wed, Apr 18, 2012 at 8:09 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
> On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote:
>
> On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote:
> On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote:
>
> Hi,
>
> I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0.
>
> I've been getting recursive errors, where one error is reported
> multiple times. It's quite spectacular in a long suite, with the
> errors overflowing the console buffer. I've whittled down a simple
> example:
>
> require 'spec_helper'
> describe "public pages" do
> subject { page }
> describe "details page" do
> before do
> visit root_path
> end
> describe "when visiting a second page before example" do
> before { visit sign_in_path }
> it { should have_link("Sign in") }
> end
> end
> end
>
> The error here is that "sign_in_path" should really be "signin_path".
> But I get that error five times, and when I run with --format
> documentation, it looks like RSpec is generating it recursively before
> it "blows up" with a stack trace (see output below).
>
> Obviously this test doesn't really need two before blocks, but
> sometimes I do want to visit two pages before a test.
>
> Am I doing something wrong, or is this a bug?
>
> Mark Berry
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Test output:
>
> [myproject (tests)]$ rspec spec/requests/test2* --format documentation
> No DRb server is running. Running in local process instead ...
>
> public pages
> details page
> when no user is signed in
> when visiting a second page before example
> when visiting a second page before example
> when no user is signed in
> when visiting a second page before example
> details page
> when no user is signed in
> when visiting a second page before example
>
> Failures:
>
> 1) public pages details page when no user is signed in when visiting
> a second page before example
> Failure/Error: before { visit sign_in_path }
> NameError:
> undefined local variable or method `sign_in_path' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460>
> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
> <top (required)>'
>
> 2) public pages details page when no user is signed in when visiting
> a second page before example
> Failure/Error: before { visit sign_in_path }
> NameError:
> undefined local variable or method `sign_in_path' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460>
> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
> <top (required)>'
>
> 3) public pages details page when no user is signed in when visiting
> a second page before example
> Failure/Error: before { visit sign_in_path }
> NameError:
> undefined local variable or method `sign_in_path' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460>
> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
> <top (required)>'
>
> 4) public pages details page when no user is signed in when visiting
> a second page before example
> Failure/Error: before { visit sign_in_path }
> NameError:
> undefined local variable or method `sign_in_path' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460>
> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
> <top (required)>'
>
> 5) public pages details page when no user is signed in when visiting
> a second page before example
> Failure/Error: before { visit sign_in_path }
> NameError:
> undefined local variable or method `sign_in_path' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460>
> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
> <top (required)>'
>
>
> This is what I would expect. There is nothing "recursive" about this. There
> is a failure in
> a before block that runs before every example. It's the same as if you had
> the same
> broken code directly in each example.
>
>
> HTH,
> David
>
>
> [Sorry if this starts a new thread. I was attempting to monitor and
> reply to the group through Google Groups, but apparently that mirror
> stopped working on April 10, so I'm having to reconstruct this reply.]
>
> Thanks for the reply.
>
> Although the output says "5 examples, 5 failures," there is only one
> example, hence my confusion about it failing five times. Also, the
> "documentation" output lists each describe block (except the first)
> two to four times.
>
> When I fix the error, I get one line per describe, plus one example
> completed, as expected:
>
>
> [myproject (tests)]$ rspec spec/requests/test2* --format documentation
>
> public pages
> details page
> when visiting a second page before example
> should has link "Sign in"
>
> Finished in 1.44 seconds
> 1 example, 0 failures
>
>
> I have since discovered that the problem only occurs when using
> "--format documentation". Without that, with the error back in place,
> RSpec only gives me one error, not five:
>
>
> [myproject (tests)]$ rspec spec/requests/test2*
> F
>
> Failures:
>
> 1) public pages details page when visiting a second page before example
> Failure/Error: before { visit sign_in_path }
> NameError:
> undefined local variable or method `sign_in_path' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0xa1f2ef8>
> # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in
> <top (required)>'
>
> Finished in 1.07 seconds
> 1 example, 1 failure
>
> Failed examples:
>
> rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details
> page when visiting a second page before example
>
> Does that clarify the issue?
>
> Yes. Is the repo public?

No, but I think it will duplicate the issue if you drop this into into
almost any project with a root_path.

spec/requests/test_spec.rb

require 'spec_helper'
describe "public pages" do
 subject { page }
 describe "details page" do
   before do
     visit root_path
   end
   describe "when visiting a second page before example" do
     before { visit sign_in_path }
     it { should have_link("Sign in") }
   end
 end
end

gemfile:

gem 'rails', '3.1.3'
gem 'devise', '1.5.3' # required to succeed, but not to fail
group :test do
  gem 'rspec-rails', '2.9.0'
  gem 'capybara', '1.1.2'
end

Run:

rspec spec/requests/test* --format documentation

Or try with another failing test. I see the issue with any failing
test if I "--format documentation".

If it doesn't duplicate, let me know and I'll try to build a public
mini project.

I've seen mention of another recursion issue traced back to Ruby 1.9;
don't know if this is related:

http://myronmars.to/n/dev-blog/2011/11/recent-rspec-configuration-warnings-and-errors

Mark Berry


More information about the rspec-users mailing list