capybara: within conflicts with RSpec 3

Use this self-contained gist to recreate the issue: https://gist.github.com/bilus/7213a2914a8bb33cefb7

Dependencies: ruby 2.1.2 capybara 2.4.4 rspec 3.2.0 sinatra 1.4.6

Problem: It doesn’t fill in email and name, find doesn’t work as well.

To make it pass, comment out include RSpec::Matchers in line 38.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

@bilus

For this simple app, to make test pass, you need only to swap includes:

class TestApp < MiniTest::Unit::TestCase
  include RSpec::Matchers
  include Capybara::DSL

  def test_title_exists
    visit '/'
    within('#main-form') do
      fill_in 'email', with: 'user@example.com'
      fill_in 'name', with: 'Joe Public'
      click_button 'submit'
    end
    assert has_content?('Congratulations')
  end
end

In this way Capybara::DSL overwrites within from RSpec::Matchers and test pass. I don’t know, how you setup your Cucumber configuration. But try to change the way you include module or require library. So RSpec should go before Capybara.