Skip to content

Loading…

Support Gem::Version properly #1024

Closed
wants to merge 1 commit into from

4 participants

@knewter

I haven't tested this with rails < 4-master, but this fixes breakage where Rails.version now returns a Gem::Version and these comparisons fail there. This is the offending commit afaict: rails/rails@c07e151

@jnicklas
Owner

That seems weird. Comparing string sizes like this seems incorrect to me. For example:

>> "3.1.2.beta1" > "3.1.2"
=> true
@knewter

That's an excellent point, though I have no idea what to_f did with that. I didn't even consider that case, though it's obvious now. How is Gem::Version intended to be compared?

@abotalov
Collaborator

Here's even more weird example:

'3.1.2' > '3.1.10' # => true 

What about <=>:
Rails.version >= Gem::Version(3.0)

@jnicklas
Owner

@abotalov if Rails previously returned something other than a Gem::Version that might break on older versions.

@abotalov
Collaborator

@jnicklas What about:

if Rails.version.is_a?(String)
  Gem::Version.new(Rails.version) >= Gem::Version.new(3.0)
else
 Rails.version >= Gem::Version.new(3.0)
end
@jnicklas
Owner

I'm not even sure what it was before, was it really a string?

@abotalov
Collaborator

@jnicklas

1.9.3p286 :015 > Rails.version
 => "3.2.11" 
@eval

How about:

Gem::Version.new(Rails.version) >= Gem::Version.new(3)

This is compatible with Rails.version being a string or Gem::Version

@elabs-dev elabs-dev pushed a commit that closed this pull request
Kim Burgestrand Make sure we are comparing gem versions, closes #1024
Due to rails/rails#8501, we can no longer case the Rails version to a float. This version should hopefully work on both Rails 4 master and on Rails 3.
78e3a48
@elabs-dev elabs-dev closed this in 78e3a48
@jnicklas jnicklas added a commit that referenced this pull request
Kim Burgestrand Make sure we are comparing gem versions, closes #1024
Due to rails/rails#8501, we can no longer case the Rails version to a float. This version should hopefully work on both Rails 4 master and on Rails 3.
6d0a7da
@jnicklas
Owner

I cherry picked this onto 2.0_stable and released it as 2.0.3 together with another tweak. A simple bundle update capybara should now fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 24, 2013
  1. @knewter

    Support Gem::Version properly

    knewter committed
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/capybara/rails.rb
View
2 lib/capybara/rails.rb
@@ -3,7 +3,7 @@
Capybara.app = Rack::Builder.new do
map "/" do
- if Rails.version.to_f >= 3.0
+ if Rails.version.to_s >= "3.0"
run Rails.application
else # Rails 2
use Rails::Rack::Static
Something went wrong with that request. Please try again.