Skip to content

Commit 1ff201e

Browse files
committed
try using methods
1 parent 2a11b69 commit 1ff201e

File tree

3 files changed

+38
-46
lines changed

3 files changed

+38
-46
lines changed

spec/system/add_new_comment_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,61 @@
77
describe "Add new comment" do
88
context "when React Router", page: :main, js: true, type: :system do
99
context "with Horizontal Form" do
10-
include_examples "with Horizontal Form"
10+
select_horizontal_form(page)
1111
include_examples "New Comment Submission", true
12-
include_examples "Validation errors displaying"
12+
check_errors(page)
1313
end
1414

1515
context "with Inline Form" do
16-
include_examples "with Inline Form"
16+
select_inline_form(page)
1717
include_examples "New Comment Submission", true
18-
include_examples "Validation errors displaying"
18+
check_errors(page)
1919
end
2020

2121
context "with Stacked Form" do
22-
include_examples "with Stacked Form"
22+
select_stacked_form(page)
2323
include_examples "New Comment Submission", true
24-
include_examples "Validation errors displaying"
24+
check_errors(page)
2525
end
2626
end
2727

2828
context "when React/Redux", page: :react_demo, js: true, type: :system do
2929
context "with Horizontal Form" do
30-
include_examples "with Horizontal Form"
30+
select_horizontal_form(page)
3131
include_examples "New Comment Submission", true
32-
include_examples "Validation errors displaying"
32+
check_errors(page)
3333
end
3434

3535
context "with Inline Form" do
36-
include_examples "with Inline Form"
36+
select_inline_form(page)
3737
include_examples "New Comment Submission", true
38-
include_examples "Validation errors displaying"
38+
check_errors(page)
3939
end
4040

4141
context "with Stacked Form" do
42-
include_examples "with Stacked Form"
42+
select_stacked_form(page)
4343
include_examples "New Comment Submission", true
44-
include_examples "Validation errors displaying"
44+
check_errors(page)
4545
end
4646
end
4747

4848
context "when simple page", page: :simple, js: true, type: :system do
4949
context "with Horizontal Form" do
50-
include_examples "with Horizontal Form"
50+
select_horizontal_form(page)
5151
include_examples "New Comment Submission", false
52-
include_examples "Validation errors displaying"
52+
check_errors(page)
5353
end
5454

5555
context "with Inline Form" do
56-
include_examples "with Inline Form"
56+
select_inline_form(page)
5757
include_examples "New Comment Submission", false
58-
include_examples "Validation errors displaying"
58+
check_errors(page)
5959
end
6060

6161
context "with the Stacked Form" do
62-
include_examples "with Stacked Form"
62+
select_stacked_form(page)
6363
include_examples "New Comment Submission", false
64-
include_examples "Validation errors displaying"
64+
check_errors(page)
6565
end
6666
end
6767
end

spec/system/edit_comment_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
click_link "Edit", match: :first
1414
let(:edited_name) { "Abraham Lincoln" }
1515

16-
include_context "when Form Submitted", name: :edited_name
16+
submit_form(name: :edited_name, text: "dude!")
1717
expect(page).to have_css(".comment", text: :edited_name)
1818
expect(page).to have_css("#notice", text: "Comment was successfully updated.")
1919
end

spec/system/shared/examples.rb

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let(:name) { "John Smith" }
99
let(:text) { "Hello there!" }
1010

11-
include_context "Form Submitted", name: :name, text: :text
11+
submit_form(name: :name, text: :text)
1212

1313
scenario "when comment is added" do
1414
expect(page).to have_css(".js-comment-author", text: name)
@@ -36,60 +36,52 @@
3636
context "with iframe text" do
3737
let(:iframe_text) { '<iframe src="http://www.w3schools.com"></iframe>' }
3838

39-
include_context "Form Submitted", text: :iframe_text
39+
submit_form(name: "", text: :iframe_text)
4040

4141
scenario "doesn't add an iframe" do
4242
expect(page).not_to have_css("iframe")
4343
end
4444
end
4545
end
4646

47-
shared_examples "Validation errors displaying" do
48-
context "when the new comment is submitted with blank fields", blank_form_submitted: true do
49-
scenario "validation errors displayed" do
50-
expect(page).to have_content("Your comment was not saved!")
51-
expect(page).to have_content("Author: can't be blank")
52-
expect(page).to have_content("Text: can't be blank")
47+
def check_errors(page)
48+
expect(page).to have_content("Your comment was not saved!")
49+
expect(page).to have_content("Author: can't be blank")
50+
expect(page).to have_content("Text: can't be blank")
5351

54-
# with a successful consequent comment submitted
55-
# the validation warnings should disappear
56-
fill_in "Your Name", with: "Some name"
57-
fill_in "Say something using markdown...", with: "Some text"
58-
click_button "Post"
52+
# with a successful consequent comment submitted
53+
# the validation warnings should disappear
54+
fill_in "Your Name", with: "Some name"
55+
fill_in "Say something using markdown...", with: "Some text"
56+
click_button "Post"
5957

60-
expect(page).to have_no_content("Your comment was not saved!")
61-
expect(page).to have_no_content("Author: can't be blank")
62-
expect(page).to have_no_content("Text: can't be blank")
63-
end
64-
end
58+
expect(page).to have_no_content("Your comment was not saved!")
59+
expect(page).to have_no_content("Author: can't be blank")
60+
expect(page).to have_no_content("Text: can't be blank")
6561
end
6662

6763
# Forms
68-
shared_examples "with Inline Form" do
64+
def select_inline_form(page)
6965
click_link "Inline Form"
7066
expect(page).to have_css("form.commentForm.form-inline")
7167
end
72-
shared_examples "with Stacked Form" do
68+
def select_stacked_form(page)
7369
click_link "Stacked Form"
7470
expect(page).to have_css("form.commentForm.form-stacked")
7571
end
76-
shared_examples "with Horizontal Form" do
77-
include_examples "with Inline Form"
72+
def select_horizontal_form(page)
73+
select_inline_form(page)
7874
click_link "Horizontal Form"
7975
expect(page).to have_css("form.commentForm.form-horizontal")
8076
end
8177

8278
# Form Submission
83-
shared_examples "when Form Submitted", form_submitted: true do |name: "Spicoli", text: "dude!"|
79+
def submit_form(name: "Spicoli", text: "dude!")
8480
fill_in "Your Name", with: name
8581
fill_in "Say something using markdown...", with: text
8682
click_button "Post"
8783
end
8884

89-
shared_examples "when Form Submitted with Blank Fields", blank_form_submitted: true do
90-
include_context "Form Submitted", name: "", text: ""
91-
end
92-
9385
shared_examples "when from classic page" do
9486
click_link "New Comment"
9587

0 commit comments

Comments
 (0)