Skip to content

Commit 31f728c

Browse files
author
Rhys Powell
committed
Passing questions feature
1 parent d3a966b commit 31f728c

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

features/questions.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: CRUD actions for question
2+
3+
As a user of the site, I can perform standard CRUD actions on questions
4+
5+
Scenario: Create a question
6+
When I create a new question
7+
Then I should be told the question was created
8+
And I should be able to see the new question
9+
10+
Scenario: Update a question
11+
Given I am a user that has created a question
12+
When I edit that question
13+
Then I should be told the question was updated
14+
And I should see that the question was updated
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
When /^I create a new question$/ do
2+
step %{a logged in user}
3+
visit new_question_path
4+
fill_in("Title", with: "My Question")
5+
fill_in("Description", with: "My Description")
6+
click_button "Ask Everyone"
7+
end
8+
9+
Then /^I should be told the question was created$/ do
10+
page.should have_content("Question Asked")
11+
end
12+
13+
Then /^I should be able to see the new question$/ do
14+
click_link("My Question")
15+
page.should have_content("My Question")
16+
page.should have_content("My Description")
17+
end
18+
19+
Given /^I am a user that has created a question$/ do
20+
step %{a logged in user}
21+
@question = Question.new(:title => "A question",
22+
:description => "The description")
23+
@question.user = @user
24+
@question.save
25+
end
26+
27+
When /^I edit that question$/ do
28+
visit "/questions/#{@question.id.to_s}/edit"
29+
fill_in "Title", with: "An edited question"
30+
fill_in "Description", with: "Just a quick edit"
31+
click_button "Ask Everyone"
32+
end
33+
34+
Then /^I should be told the question was updated$/ do
35+
page.should have_content("successfully updated")
36+
end
37+
38+
Then /^I should see that the question was updated$/ do
39+
page.should have_content('An edited question')
40+
page.should have_content('Just a quick edit')
41+
end

features/step_definitions/user_steps.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Given /^a logged in user$/ do
2-
@user = User.create!(username: "test_user",
1+
def login_user
2+
@user = User.create!(username: "test_user",
33
email: "test_user@example.com",
44
password: "foobar",
55
password_confirmation: "foobar")
@@ -9,6 +9,10 @@
99
click_button("Sign in")
1010
end
1111

12+
Given /^a logged in user$/ do
13+
login_user unless @user
14+
end
15+
1216
When /^I go to look at my profile page$/ do
1317
visit user_path(@user)
1418
end

0 commit comments

Comments
 (0)