Cos*_*sti 17 ruby-on-rails cucumber
我正在写一个使用SaS的网络应用程序.每个客户都有自己的db和app目录,所以我有一个rake任务,它创建了运行他们网站的所有必要的最小数据(种子数据):默认权限和角色,superadmin用户,已经填充的"us_states"表,一些本地仓库和终端(这是一个物流应用程序).
我没有任何黄瓜方案,我刚刚开始构建一些.我是黄瓜初学者.
我首先将种子数据任务放在Given行中,但这几乎适用于所有场景,并且对于那些查看场景的非程序员来说没有多大意义(对于人类而言,它是如此给定的它不需要有意识地表达)所以我把它移到了hooks.rb.
我的第一个场景看起来像这样:
Run Code Online (Sandbox Code Playgroud)
1 Feature: Place an order
2 In order to keep orders in the database
3 As a admin
4 I want to place orders
5
6 Scenario: Using common legs
7 Given I have 1 customers
8 And I'm on the homepage
9 And I follow "Place an Order"
10 When I select the customer
11 And I select the SSLine
12 And I click "Use Common Legs"
13 Then I should see "PICKUP AT"
14 And I should see "DELIVER TO" or "LOAD AT"
15 And I should see EMPTY RETURN
我的hooks.rb看起来像这样:
1 Before do
2 MinimumData.new('costi', '1234').populate #username and password
3 end
Run Code Online (Sandbox Code Playgroud)
问题:
Geo*_*tte 22
我不知道before(:all)黄瓜的等价物.您可以做的是将您的种子添加到文件中features/support/seeds.rb,然后在您features/support/env.rb的行顶部和下方需要environment.rb放置行:
require File.dirname(__FILE__) + '/seeds'
Run Code Online (Sandbox Code Playgroud)
或者
#just write the code you want to execute directly into the env.rb file
Run Code Online (Sandbox Code Playgroud)
这些是您可以添加的可用块 env.rb
Before do
#this code is run before each scenario
end
after do
#this code is run after each scenario
end
at_exit do
#this code is run at the end
end
Run Code Online (Sandbox Code Playgroud)
对Geoff Lanotte的答案进行了一次修正.它应该是
Before do # this code is run before each scenario end
与首都B.
但是,您可能希望将它放在feature/support目录中的新文件中,而不是将此类代码放在env.rb文件中,例如"hooks.rb"文件.这是因为如果升级cucumber-rails,则会自动重新生成env.rb文件.
更多信息请访问:https://github.com/cucumber/cucumber/wiki/Hooks
| 归档时间: |
|
| 查看次数: |
6982 次 |
| 最近记录: |