Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `collect' for nil:NilClass error when running rspec spec with -fd flag #13

Open
reconstructions opened this issue Jun 10, 2014 · 4 comments

Comments

@reconstructions
Copy link

I have some unusual failures when using this gem in rspec tests:

If I run rspec like this:

rspec spec/ -fd

Setlist pages
  setlist#new
    should be valid markup (FAILED - 9)
    should have content "Add a New Setlist"
    should have title "Add A Setlist | The San Francisco Rockers' Club"

1) Shared Pages: menus, headers, footers page header main menu with a logged in user should be valid markup
   Failure/Error: it { should be_valid_markup }
   NoMethodError:
     undefined method `collect' for nil:NilClass
   # ./spec/requests/shared_pages_spec.rb:31:in `block (5 levels) in <top (required)>'

 Finished in 19.53 seconds
 320 examples, 17 failures, 3 pending

I get lots of failures from should be_valid_markup, in all the tests where I use it.

If I run my tests like this:

rspec spec/ --tag request -fd

Setlist pages
  setlist#new
    should be valid markup
    should have content "Add a New Setlist"
    should have title "Add A Setlist | The San Francisco Rockers' Club

Finished in 29.55 seconds
94 examples, 0 failures

Or this:

rspec spec/

Finished in 32.75 seconds
320 examples, 0 failures, 3 pending

They all pass.

Any idea what is going on here? This gem has helped me keep my HTML valid, so thanks for that!

@reconstructions
Copy link
Author

Additional weird behavior, no errors:

$ rspec spec/requests/setlists_pages_spec.rb
................................

Finished in 8.43 seconds

Same code, different rspec invocation:

$ rspec spec/

Failures:

1) Setlist pages setlist#show should be valid markup
   Failure/Error: it { should be_valid_markup }
   NoMethodError:
     undefined method `collect' for nil:NilClass
   # ./spec/requests/setlists_pages_spec.rb:59:in `block (3 levels) in <top (required)>'

...and 8 more...

Finished in 35.34 seconds
330 examples, 9 failures, 3 pending

This time, the failures occurred in only one rspec file, whereas other files with be_valid_markup calls passed.

@reconstructions
Copy link
Author

Also found some invalid HTML in Devise's markup using your gem:

(heartcombo/devise#3067)

(heartcombo/devise#3066)

@h-lame
Copy link
Contributor

h-lame commented Jun 11, 2014

Can you give us a little bit more information: e.g. rspec version, full stack trace of where the error occurs, etc?

@reconstructions
Copy link
Author

My rspec version: gem "rspec-rails", "~> 2.14.1"

Here's a typical stack trace. Looks like `be_valid_asset' might be tangling with the 'representable' gem in some way:

Failures:

  1) CSS Validation validate all .css files in '/public/assets/
     Failure/Error: css.should be_valid_css3
     NoMethodError:
       undefined method `collect' for nil:NilClass
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/representable-1.8.5/lib/representable/bindings/hash_bindings.rb:40:in `serialize'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/representable-1.8.5/lib/representable/bindings/hash_bindings.rb:22:in `write'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/representable-1.8.5/lib/representable/hash/collection.rb:23:in `create_representation_with'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/representable-1.8.5/lib/representable/hash.rb:39:in `to_hash'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/roar-0.12.7/lib/roar/representer/json.rb:26:in `to_hash'
     # /Users/reconstructions/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:567:in `try_convert'
     # /Users/reconstructions/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:567:in `start'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/be_valid_asset-1.2.3/lib/be_valid_asset/be_valid_base.rb:94:in `http_start'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/be_valid_asset-1.2.3/lib/be_valid_asset/be_valid_base.rb:72:in `call_validator'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/be_valid_asset-1.2.3/lib/be_valid_asset/be_valid_base.rb:58:in `get_validator_response'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/be_valid_asset-1.2.3/lib/be_valid_asset/be_valid_base.rb:17:in `validate'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/be_valid_asset-1.2.3/lib/be_valid_asset/be_valid_css.rb:24:in `matches?'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:24:in `handle_matcher'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-expectations-2.14.5/lib/rspec/expectations/syntax.rb:53:in `should'
     # ./spec/assets/css_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./spec/assets/css_spec.rb:6:in `foreach'
     # ./spec/assets/css_spec.rb:6:in `block (2 levels) in <top (required)>'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `instance_eval'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `block in run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `call'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `call'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:446:in `run_hook'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:111:in `run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:390:in `block in run_examples'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `map'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `run_examples'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:371:in `run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `map'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block in run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/reporter.rb:58:in `report'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:25:in `run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
     # /Users/reconstructions/.rvm/gems/ruby-2.1.0@sfrc/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants