ruby-on-rails - 将 cucumber 翻译成 rspec

标签 ruby-on-rails testing rspec cucumber

如何在 rspec 中编写以下功能?

Feature: Signing in; In order to use the site as a user, I want to be able to sign in

  Scenario: Signing in via confirmation
    Given there are the following users:
      |email            |password|
      |user@example.com |password|
    And "user@example.com" opens the mail with subject
      "Confirmation instructions"
    And they click the first link in the email
    Then I should see "Your account was successfully confirmed"
    And I should see "Signed in as user@example.com"

最佳答案

这看起来像是 Rails 3 in Action 第一版中的功能,我目前正在将其重写到第二版中。第二版的特点是这样的:

feature 'Signing in' do
  before do
    Factory(:user, :email => "ticketee@example.com")
  end

  scenario 'Signing in via confirmation' do
    open_email "ticketee@example.com", :with_subject => /Confirmation/
    click_first_link_in_email
    page.should have_content("Your account was successfully confirmed")
    page.should have_content("Signed in as ticketee@example.com")
  end
end

这是使用 Capybara 的新功能语法,其所有意图和目的与 RSpec 的 context block 相同。通过使用 before,您可以设置一个可以在此功能中使用的用户。在该场景中,您使用 open_email 方法(由 email_spec gem 提供)打开电子邮件,并使用该 gem 提供的 click_first_link_in_email 方法来执行这两个步骤。

然后会将您带到一个页面,您应该能够在其中看到所需的两条消息。

关于ruby-on-rails - 将 cucumber 翻译成 rspec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10404594/

相关文章:

iphone - 设计 Omniauth 和 Iphone/Android 应用程序

java - 与功能文件不同的模块中的 CUCUMBER 功能定义

ruby-on-rails - 包括标签和其他无标签测试?

ruby-on-rails-3 - 如何在 Rails 中 stub 路径生成方法?

ruby-on-rails - 如何立即与 guard 和工厂女孩一起检查工厂?

ruby-on-rails - 如何从 Ruby 中的单词数组中获取所有对角线?

ruby-on-rails - 如何使用 Devise 向 Rails 中的新注册用户发送欢迎电子邮件?

r - 手动检查 R 中的面板单位根测试

ruby - 类方法 : describe "#my_class_method" or describe "#self.my_class_method"?

javascript - 在没有 Assets 管道的情况下使用 Turbolinks?