./features/blog.features . For each property, we also describe the concepts of Why, Who and What (In order, A, Should). These are BDD wishes, in fact they do not affect the result, but they help us to formulate more clearly what we want from this feature.Feature: Post articles In order to show trip photos A owner Should be abble to post article Feature: Make comments In order to contact A user Should be abble to make comments
Feature: Post articles
In order to show trip photos
A owner
Should be abble to post article
Scenario: Post article by owner
Given I signed up as owner
When I write article "About my last nigh trip"
"It was very hard night .."
And I post article
Then I should see "Article is created"
Scenario: Post article by user
Given I signed up as user
When I write article "My fantazy"
And text of article is "..no more"
And I post article
Then I should see "you have no access to post articles"
> cucumber features / blog.features ... 2 scenarios (2 undefined) 12 steps (12 undefined) 0m0.012s You can implement step definitions for undefined steps with these snippets: Given / ^ I signed up as owner $ / do pending end When / ^ I write article "([^ \"] *) "$ / do | arg1 | pending end When / ^ text of article is "([^ \"] *) "$ / do | arg1 | pending end When / ^ I post article $ / do pending end Then / ^ I should see "([^ \"] *) "$ / do | arg1 | pending end
/features/step_definitions/blog_steps.rb and prescribe actions, for example: Given / ^ I signed up as (. *) $ / Do | role |
current_user = User.find_by_role (role)
end
When / ^ I write article "([^ \"] *) "$ / do | arg1 |
aricle = Article.create (: subject => arg1,: user => user)
same_subject = subject
end
When / ^ text of article is "([^ \"] *) "$ / do | arg1 |
aricle.text = arg1
end
When / ^ I post article $ / do
artricle.save!
end
Then / ^ I should see "([^ \"] *) "$ / do | arg1 |
response.should contain (arg1)
end
> cucumber features / blog.features
Feature: Post articles
In order to show trip photos
A owner
Should be abble to post article
Scenario: Post article by owner # features / blog.features: 6
Given I signed up as owner # features / step_definitions / blog_steps.rb: 1
uninitialized constant User (NameError)
features / blog.features: 7: in `Given I signed up as owner '
When I write the article "About my last nigh trip" # features / step_de
Cucumber, Shoulda and the webrat wizard.Source: https://habr.com/ru/post/62958/
All Articles