ruby-on-rails - visit 和 current_path 与 .should 在 rails 中的使用有什么区别?

标签 ruby-on-rails testing capybara rspec-rails

Then /^I should be on the free signup page$/ do
  *current_path.should == free_signup_path* 
end

Then /^I should be on the free signup page$/ do
   *visit free_signup_path* 
end

这两个有什么区别?

最佳答案

#visit 告诉浏览器转到一个新的 url 并将向正在测试的应用程序发起获取请求。 #current_path 可让您读取浏览器所在的当前位置。

注意:在验证当前路径时,您应该停止使用 current_path.should == some_path,而是使用 page.should have_current_path(some_path)。 have_current_path 匹配器包括等待行为,将有助于减少使用支持 JS 的驱动程序的测试

关于ruby-on-rails - visit 和 current_path 与 .should 在 rails 中的使用有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35667106/

相关文章:

ruby-on-rails - 如何从终端中删除这条线(在图片中)?

ruby-on-rails - Rails 3 -"Couldn' t find [model] without an ID”问题

android - 如何在没有 IdlingResource 的情况下在 Espresso 中等待异步任务

ruby-on-rails - capybara NoMethodError : undefined method `visit' for

ruby - 切换到 cucumber , capybara 中的弹出窗口

ruby-on-rails - Rails 单元测试 - 未定义的方法 'users'

ruby-on-rails - 使用 Rails 4.0 的工厂女孩

javascript - Angular 6 创建 TemplateRef 的实例

java - 添加 @after 钩子(Hook)会影响包中的所有测试

ruby-on-rails - 尝试使用 Capybara、Cucumber、RSpec 和 Devise 登录时重定向到 example.com