Skip to content

Commit

Permalink
Reset Capybara's monkey patch on old versions.
Browse files Browse the repository at this point in the history
Apps just upgrading to RSpec 3 are more likely to have several
conditions which may cause a poor user experience:

- Version of Capybara prior to 2.4.0
- Loading Capybara before rspec-rails in `spec/spec_helper.rb`
- Not enabling monkey patch mode or have set:

  `config.expose_dsl_globally = false`

When these conditions are all met our `feature` alias is exposed
globally overwriting the Capybara monkey patch. This will cause all
feature specs to be skipped.

For a user attempting to upgrade an app this can be a very frustrating,
and confusing, "bug".
  • Loading branch information
cupakromer committed Dec 31, 2014
1 parent cb69a9e commit 56117e7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rspec/rails/example/feature_example_group.rb
Expand Up @@ -46,17 +46,27 @@ def visit(*)
EOT
}

# Capybara's monkey patching causes us to have to jump through some hoops
top_level = self
main_feature = nil
if defined?(Capybara) && ::Capybara::VERSION.to_f < 2.4
# Capybara 2.2 and 2.3 do not use `alias_example_xyz`
opts[:skip] = <<-EOT.squish
Capybara < 2.4.0 does not support RSpec's namespace or
`config.expose_dsl_globally = false`. Upgrade to Capybara >= 2.4.0.
EOT
main_feature = top_level.method(:feature) if top_level.respond_to?(:feature)
end

RSpec.configure do |c|
main_feature = nil unless c.expose_dsl_globally?
c.alias_example_group_to :feature, opts
c.alias_example_to :scenario
c.alias_example_to :xscenario
end

# Due to load order issues and `config.expose_dsl_globally?` defaulting to
# `true` we need to put Capybara's monkey patch method back. Otherwise,
# app upgrades have a high likelyhood of having all feature specs skipped.
top_level.define_singleton_method(:feature, &main_feature) if main_feature
end

0 comments on commit 56117e7

Please sign in to comment.