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

RSpec 4.1 breaks on Rails 4.2 #2477

Closed
tagliala opened this issue Mar 8, 2021 · 10 comments
Closed

RSpec 4.1 breaks on Rails 4.2 #2477

tagliala opened this issue Mar 8, 2021 · 10 comments

Comments

@tagliala
Copy link

tagliala commented Mar 8, 2021

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.4.10
Rails version: 4.2.11.3
RSpec version: 4.1.0

Observed behaviour

RSpec 4.1 does not work start on Rails 4.2.11.3, while 4.0 does

     Failure/Error: example.run
     
     NameError:
       undefined local variable or method `use_transactional_tests' for #<RSpec::ExampleGroups::Welcome::Index:0x00007fcb64cdbf40>
       Did you mean?  use_transactional_fixtures

Tracked down with git bisect down to 073daad

Expected behaviour

Keeps working with Rails 4.1 or gemspec specifies >= 5.0 to prevent update to 4.1

https://github.com/rspec/rspec-rails/blob/main/rspec-rails.gemspec#L36

Can you provide an example app?

Travis CI failure: https://travis-ci.org/github/diowa/ruby2-rails4-bootstrap-heroku/builds/761888443

@JonRowe
Copy link
Member

JonRowe commented Mar 8, 2021

👋 RSpec-Rails 4.x maintains a soft support for Rails 4.2, but we don't actively maintain it, if you'd like to tackle this in a PR please do and I'll release it as a bugfix.

swiehr added a commit to tools-aoeur/redmine_base_rspec that referenced this issue Mar 8, 2021
jdehaan pushed a commit to tools-aoeur/redmine_base_rspec that referenced this issue Mar 8, 2021
@yo-it-engineer
Copy link

yo-it-engineer commented Mar 10, 2021

Hi. We just encountered the same problem too. For the time being we also fixed version limited rspec-rails version to 4.0.1.

@JonRowe
Copy link
Member

JonRowe commented Mar 10, 2021

I see no changes from 4.0.1 https://github.com/rspec/rspec-rails/blob/4-1-maintenance/lib/rspec/rails/fixture_support.rb#L27

You appear to be looking at 4-1-maintenance there @pirj

@yo-it-engineer
Copy link

yo-it-engineer commented Mar 10, 2021

@pirj I'm not sure if I can explain it well, but when our Rails 4.1 4.2 system run rspec, this line caused method not found error.

NameError:
       undefined local variable or method `use_transactional_tests' for #<RSpec::ExampleGroups::Anonymous:0x000055eac3f36e08>

https://github.com/rspec/rspec-rails/blob/v4.1.1/lib/rspec/rails/fixture_support.rb#L16

the use_transactional_tests method is not exist in Rails 4.1 4.2 I guess. I think it was introduced since Rails 5.x .

I try to tweak around and this is the way I was able to get rid of the error:
image

tagliala added a commit to tagliala/rspec-rails that referenced this issue Mar 10, 2021
Rails 4.2 does not have `use_transactional_tests` defined

Fix rspec#2477
@tagliala
Copy link
Author

tagliala commented Mar 10, 2021

Hi,

I've tracked down the issue to 073daad

If you can live with a try, I have a fix at tagliala/rspec-rails@12872f9

No problems into adding a conditional against rails version or a respond_to?

edit:

I think @yo-it-engineer's solution is more accurate, but I don't know if Rails 4.2 as the same issue described in the comments, I should run specs against Rails 4.2 on my development machine

@pirj
Copy link
Member

pirj commented Mar 10, 2021

Nice research, @tagliala ! 👏

WDYT of mimicking Rails 4.2's behaviour and doing it like it does? https://github.com/rails/rails/blob/0ecaaf76d1b79cf2717cdac754e55b4114ad6599/activerecord/lib/active_record/fixtures.rb#L922
Since 5.0 this method has changed to https://github.com/rails/rails/blob/ac6aa32f7cf66264ba87eabed7c042bb60bcf3a2/activerecord/lib/active_record/fixtures.rb#L958
I'd suggest defining this method inside a if ::Rails::VERSION::STRING > '5' conditional.

tagliala added a commit to tagliala/rspec-rails that referenced this issue Mar 10, 2021
Rails 4.2 does not have `use_transactional_tests` defined

Fix rspec#2477
@tagliala
Copy link
Author

Please find a Draft PR at #2479

It contains an approach like the one suggested by @yo-it-engineer and uniform to the approach used in the included block (check for > '5', else assumes 4)

tagliala added a commit to tagliala/rspec-rails that referenced this issue Mar 10, 2021
Rails 4.2 does not have `use_transactional_tests` defined

Fix rspec#2477
@JonRowe
Copy link
Member

JonRowe commented Mar 10, 2021

Closed by #2480

@JonRowe JonRowe closed this as completed Mar 10, 2021
@JonRowe
Copy link
Member

JonRowe commented Mar 10, 2021

A fix for this will be released later today as 4.1.2.

(Please note future travellers, this does not mean we are supporting Rails 4.2 on this series of RSpec, this was an exception to the rule 😃 )

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

4 participants