2

I want to compare the expected path and current path to justify whether the test is passed within Minitest.

I found the method Capybara::SessionMatchers#assert_current_path. I guess this method can fulfill my requirement.

But when I wrote:

page.assert_current_path()

In my test, the error showed: no #assert_current_path method

I've seen the Capybara::Session has included the Capybara::SessionMatchers. I'm confused of why I cannot call the #assert_current_path method. Does Capybara have the functionality to compare current path and expected path? coz use page content to justify the result is not stable for me.

notapatch
  • 6,569
  • 6
  • 41
  • 45
Jevan Wu
  • 41
  • 4

2 Answers2

2

Make sure you're running Capybara 2.5+ - the assert_current_path matcher wasn't added until 2.5.0

page.assert_current_path('/expected/path')
notapatch
  • 6,569
  • 6
  • 41
  • 45
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
-1

Try this

uri = URI.parse(current_url)

if you need check additional params

"#{uri.path}?#{uri.query}".should == your_path(:your_params => 'your_value')
user2322409
  • 814
  • 9
  • 15
  • 2
    This compares immediately which has issues with asynchronous path changes (triggered by JS, etc) - using assert_current_path/have_current_path takes advantage of Capybaras waiting behavior – Thomas Walpole Oct 28 '15 at 05:48