Rails 有一个 Rails Sample 中有这么一段东西,是什么

xoxoj · 2012年04月13日 · 最后由 xoxoj 回复于 2012年04月13日 · 2880 次阅读
Given /^a user visits the signin page$/ do
  visit signin_path
end

When /^he submits invalid signin information$/ do
  click_button "Sign in"
end

Then /^he should see an error message$/ do
  page.should have_selector('div.alert.alert-error')
end

Given /^the user has an account$/ do
  @user = User.create(name: "Example User", email: "[email protected]",
                      password: "foobar", password_confirmation: "foobar")
end

When /^the user submits valid signin information$/ do
  visit signin_path
  fill_in "Email",    with: @user.email
  fill_in "Password", with: @user.password 
  click_button "Sign in"
end

Then /^he should see his profile page$/ do
  page.should have_selector('title', text: @user.name)
end

Then /^he should see a signout link$/ do
  page.should have_link('Sign out', href: signout_path)
end

我看了一下 Ruby on Rails Tutorial Sample App 里面的代码 有一个 features 文件夹下面有一个子文件夹下有一个文件 authentication_steps.rb 就是如上内容,请问这段内容有什么作用吗?看上去像是逻辑描述,请问在项目运行中起到什么作用吗?谢谢!

补充一下,还有一个文件是 signing_in.feature 这个.feature 的后缀之前没见过啊,里面的内容是

Feature: Signing in

  Scenario: Unsuccessful signin
    Given a user visits the signin page
    When he submits invalid signin information
    Then he should see an error message

  Scenario: Successful signin
    Given a user visits the signin page
      And the user has an account
      And the user submits valid signin information
    Then he should see his profile page
      And he should see a signout link


噢,我突然好像明白了,这个 Sample 里面用到了一个 Cucumber 黄瓜的东东。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号