13. EXAMPLE. FEATURE.
Feature: Article tags
In order to work with article tags
As a site user
I want to both create and delete tags
14. EXAMPLE. FEATURE.
Scenario: Creating a tag
Given an article exists with no tags
When I submit a new tag for the article
Then the article should have one tag
And I am redirected to the article
15. EXAMPLE. FEATURE.
Scenario: Creating a tag
Given an article exists with no tags
When I submit a new tag for the article
Then the article should have one tag
And I am redirected to the article
Scenario: Deleting a tag
Given an article exists with one tag
When I delete the article tag
Then the article should have no tags
And I am redirected to the article
16. EXAMPLE. FEATURE.
Feature: Article tags
In order to work with article tags
As a site user
I want to both create and delete tags
Scenario: Creating a tag
Given an article exists with no tags
When I submit a new tag for the article
Then the article should have one tag
And I am redirected to the article
Scenario: Deleting a tag
Given an article exists with one tag
When I delete the article tag
Then the article should have no tags
And I am redirected to the article
19. EXAMPLE. FEATURE.
Feature: Article tags
In order to work with article tags
As a site user
I want to both create and delete tags
Scenario: Creating a tag
Given an article exists with no tags
When I submit a new tag for the article
Then the article should have one tag
And I am redirected to the article
Scenario: Deleting a tag
Given an article exists with one tag
When I delete the article tag
Then the article should have no tags
And I am redirected to the article
35. DRY IT UP. REGEX MATCHING.
Given /^an article exists with no tags$/ do
@article = Article.create!(:title => quot;Beautiful Evidencequot;)
end
Given /^an article exists with one tag$/ do
@article = Article.create!(:title => quot;Beautiful Evidencequot;)
@tag = Tag.create!(:name => quot;visualisationquot;)
@tagging = @article.taggings.create!(:tag => @tag)
end
36. DRY IT UP. REGEX MATCHING.
Given /^an article exists with no tags$/ do
@article = Article.create!(:title => quot;Beautiful Evidencequot;)
end
Given /^an article exists with one tag$/ do
@article = Article.create!(:title => quot;Beautiful Evidencequot;)
@tag = Tag.create!(:name => quot;visualisationquot;)
@tagging = @article.taggings.create!(:tag => @tag)
end
Given /^an article exists with (d+) tags$/ do |num|
@article = Article.create!(:title => quot;Beautiful Evidencequot;)
num.to_i.times do |num|
@tag = Tag.create!(:name => quot;random-tag-#{num}quot;)
@tagging = @article.taggings.create!(:tag => @tag)
end
end
37. DRY IT UP. REGEX MATCHING.
Then /^the article should have one tag$/ do
@article.taggings.length.should == 1
end
Then /^the article should have no tags$/ do
@article.taggings.length.should == 0
end
38. DRY IT UP. REGEX MATCHING.
Then /^the article should have one tag$/ do
@article.taggings.length.should == 1
end
Then /^the article should have no tags$/ do
@article.taggings.length.should == 0
end
Then /^the article should have (d+) tags$/ do |num|
@article.taggings.length.should == num.to_i
end
39. DRY IT UP. REGEX MATCHING.
Feature: Article tags
In order to work with article tags
As a site user
I want to both create and delete tags
Scenario: Creating a tag
Given an article exists with no tags
When I submit a new tag for the article
Then the article should have one tag
And I am redirected to the article
Scenario: Deleting a tag
Given an article exists with one tag
When I delete the article tag
Then the article should have no tags
And I am redirected to the article
40. DRY IT UP. REGEX MATCHING.
Given an article exists with 0 tags
Then the article should have 1 tags
Given an article exists with 1 tags
Then the article should have 0 tags
42. VIEWS. RESPONSE.SHOULD
Feature: Viewing an article
In order to read an article
As a site user
I want access the article
Scenario: Viewing an article
Given an article exists with 1 tags
When I view the article
Then I should see the page
And I should see the article title
And I should see the article tag
43. VIEWS. RESPONSE.SHOULD
When /^I view the article$/ do
get article_path(@article)
end
Then /^I should see the page$/ do
response.should be_success
end
Then /^I should see the article title$/ do
response.should include_text(@article.title)
end
Then /^I should see the article tag$/ do
response.should include_text(@tag.name)
end
44. VIEWS. WEBRAT
Scenario: Submitting the add tag form
Given an article exists with 0 tags
When I visit the article page
And I submit the tag form with 'edward'
Then I am redirected to the article
And the article should have 1 tags
And the article should be tagged with 'edward'
45. VIEWS. WEBRAT
Scenario: Submitting the add tag form
Given an article exists with 0 tags
When I visit the article page
And I submit the tag form with 'edward'
Then I am redirected to the article
And the article should have 1 tags
And the article should be tagged with 'edward'
When /^I visit the article page$/ do
visit article_path(@article)
end
When /^I submit the tag form with '(w+)'$/ do |value|
fill_in quot;tagsquot;, :with => value
click_button quot;submitquot;
end
Then /^the article should be tagged with '(w+)'$/ do |value|
@article.tags.map(&:name).include?(value).should be_true
end