rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.18k stars 1.04k forks source link

Test of http response with wrong matcher never return #1129

Closed vivit-jc closed 10 years ago

vivit-jc commented 10 years ago

I found the case what never ends in controller specs. I should write test code like this:

expect(response.status).to eq(404)

But I wrote this in mistake:

expect(response).to eq(404)

and I ran rspec test, so it never ends. I'm using latest version of Rails and RSpec. What do you think about?

JonRowe commented 10 years ago

You haven't provided enough information to reproduce this, expect(response).to eq(404) should fail almost immediately, if it's not it's possibly because response is taking a very long time to return, but without further information I can't replicate this, can you produce a standalone reproduction of this?

vivit-jc commented 10 years ago

I'm sorry my inspection was not enough. I created a new rails project, generate a scaffold model and add just only gem 'rspec-rails' in Gemfile for replication. My test returned a result rightly, expect(response).to eq(404) was failed. Probably, some gem in my project cause that issue. I'm investigating what gem do it. This is my Gemfile:

source 'https://rubygems.org'

gem 'rails'
gem 'sqlite3'

gem 'execjs'
gem 'therubyracer'
gem "less-rails"

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier', '>= 1.0.3'
end

gem "slim"
gem "ruby_parser"
gem "html2haml"
gem "slim-rails"

gem 'protected_attributes'
gem 'jquery-rails'
gem 'devise'
gem 'kaminari'
gem 'twitter-bootstrap-rails'
gem 'google-analytics-rails'

group :development,:test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'guard'
end

group :test do
  gem 'faker'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'launchy'
  gem 'selenium-webdriver'
end

group :production do
  gem 'mysql2'
end

Any idea?

myronmarston commented 10 years ago

This is due to a bug in either rack (see rack/rack#419) or rails (see rails/rails#13921 and rails/rails#13982) that causes [response].flatten to recurse infinitely. Both have been fixed (although I'm not sure if the rails fix has been released) but if you upgrade to versions that have fixes the problem will go away. In the meantime, make expectations about attributes of the response rather than on the response itself.

For more history/discussion see: