Rails 3 rspec + capybara - current_path is nil?

2019-06-19 05:41发布

问题:

I have this in my users_spec.rb

  scenario "Go to contact page" do
    visit "/contact"
    current_path.should == contact_path
  end

After running rspec, I get

Failure/Error: current_path.should == contact_path
       expected: "/contact"
            got: nil (using ==)

For some reason, current_path seem to be returning nil. Is there a configuration that I am missing?

回答1:

Authors answer:

Min Ming Lo

It turns out that because webrat is also included, there was some sort of conflict. I commented out my webrat from my gem file (which I wasn't using anyway). It was included earlier for some other testing (and also due to many outdated tutorials out there).