Skip to content

Commit b9b6f00

Browse files
committed
looks like contexts can no longer contain both actions & expectations
1 parent 2a11b69 commit b9b6f00

File tree

5 files changed

+81
-129
lines changed

5 files changed

+81
-129
lines changed

spec/system/add_new_comment_spec.rb

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,78 @@
11
# frozen_string_literal: true
22

33
require "rails_helper"
4-
require "system/shared/examples"
54
require "system/shared/contexts"
65

76
describe "Add new comment" do
87
context "when React Router", page: :main, js: true, type: :system do
98
context "with Horizontal Form" do
10-
include_examples "with Horizontal Form"
11-
include_examples "New Comment Submission", true
12-
include_examples "Validation errors displaying"
9+
click_link "Inline Form"
10+
click_link "Horizontal Form"
11+
submit_form
12+
include_examples "check if comment is added", true
13+
include_examples "expect successful validation"
1314
end
1415

1516
context "with Inline Form" do
16-
include_examples "with Inline Form"
17-
include_examples "New Comment Submission", true
18-
include_examples "Validation errors displaying"
17+
click_link "Inline Form"
18+
submit_form
19+
include_examples "check if comment is added", true
20+
include_examples "expect successful validation"
1921
end
2022

2123
context "with Stacked Form" do
22-
include_examples "with Stacked Form"
23-
include_examples "New Comment Submission", true
24-
include_examples "Validation errors displaying"
24+
click_link "Stacked Form"
25+
submit_form
26+
include_examples "check if comment is added", true
27+
include_examples "expect successful validation"
2528
end
2629
end
2730

2831
context "when React/Redux", page: :react_demo, js: true, type: :system do
2932
context "with Horizontal Form" do
30-
include_examples "with Horizontal Form"
31-
include_examples "New Comment Submission", true
32-
include_examples "Validation errors displaying"
33+
click_link "Inline Form"
34+
click_link "Horizontal Form"
35+
submit_form
36+
include_examples "check if comment is added", true
37+
include_examples "expect successful validation"
3338
end
3439

3540
context "with Inline Form" do
36-
include_examples "with Inline Form"
37-
include_examples "New Comment Submission", true
38-
include_examples "Validation errors displaying"
41+
click_link "Inline Form"
42+
submit_form
43+
include_examples "check if comment is added", true
44+
include_examples "expect successful validation"
3945
end
4046

4147
context "with Stacked Form" do
42-
include_examples "with Stacked Form"
43-
include_examples "New Comment Submission", true
44-
include_examples "Validation errors displaying"
48+
click_link "Stacked Form"
49+
submit_form
50+
include_examples "check if comment is added", true
51+
include_examples "expect successful validation"
4552
end
4653
end
4754

4855
context "when simple page", page: :simple, js: true, type: :system do
4956
context "with Horizontal Form" do
50-
include_examples "with Horizontal Form"
51-
include_examples "New Comment Submission", false
52-
include_examples "Validation errors displaying"
57+
click_link "Inline Form"
58+
click_link "Horizontal Form"
59+
submit_form
60+
include_examples "check if comment is added", false
61+
include_examples "expect successful validation"
5362
end
5463

5564
context "with Inline Form" do
56-
include_examples "with Inline Form"
57-
include_examples "New Comment Submission", false
58-
include_examples "Validation errors displaying"
65+
click_link "Inline Form"
66+
submit_form
67+
include_examples "check if comment is added", false
68+
include_examples "expect successful validation"
5969
end
6070

6171
context "with the Stacked Form" do
62-
include_examples "with Stacked Form"
63-
include_examples "New Comment Submission", false
64-
include_examples "Validation errors displaying"
72+
click_link "Stacked Form"
73+
submit_form
74+
include_examples "check if comment is added", false
75+
include_examples "expect successful validation"
6576
end
6677
end
6778
end

spec/system/destroy_comment_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
let(:comment) { Comment.first }
99

1010
it "clicking destroy link destroys comment" do
11-
include_examples "when from classic page"
11+
click_link "New Comment"
12+
submit_form(name: comment.author, text: comment.text)
13+
1214
accept_confirm do
1315
click_link "Destroy", href: comment_path(comment)
1416
end
17+
1518
expect(page).not_to have_css(".comment", text: comment.author)
1619
expect(page).not_to have_css(".comment", text: comment.text)
1720
end

spec/system/edit_comment_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99

1010
context "when from classic page" do
1111
it "comment is updated when edit is submitted" do
12-
include_examples "when from classic page"
12+
click_link "New Comment"
13+
submit_form
14+
1315
click_link "Edit", match: :first
1416
let(:edited_name) { "Abraham Lincoln" }
1517

16-
include_context "when Form Submitted", name: :edited_name
18+
subit_form(name: :edited_name)
1719
expect(page).to have_css(".comment", text: :edited_name)
1820
expect(page).to have_css("#notice", text: "Comment was successfully updated.")
1921
end
2022

2123
it "comment is not updated when edit is submitted with blank fields", blank_form_submitted: true do
22-
include_examples "when from classic page"
24+
click_link "New Comment"
25+
submit_form
26+
2327
click_link "Edit", match: :first
28+
submit_form(name: "", text: "")
29+
2430
expect(page).not_to have_success_message
2531
expect(page).to have_failure_message
2632
expect(page).not_to have_css(".comment", text: "")

spec/system/shared/contexts.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,32 @@
2020
shared_context "when Existing Comment", existing_comment: true do
2121
before { Comment.create(author: "John Doe", text: "Hello there!") }
2222
end
23+
24+
shared_examples "check if comment is added" do |expect_comment_count|
25+
expect(page).to have_css(".js-comment-author", text: name)
26+
expect(page).to have_css(".js-comment-text", text: text)
27+
expect(page).to have_no_content("Your comment was not saved!")
28+
if expect_comment_count
29+
expect(page).to have_css("#js-comment-count",
30+
text: "Comments: #{Comment.count}")
31+
end
32+
end
33+
34+
shared_examples "expect failed validation" do
35+
expect(page).to have_content("Your comment was not saved!")
36+
expect(page).to have_content("Author: can't be blank")
37+
expect(page).to have_content("Text: can't be blank")
38+
end
39+
40+
shared_examples "expect successful validation" do
41+
expect(page).to have_no_content("Your comment was not saved!")
42+
expect(page).to have_no_content("Author: can't be blank")
43+
expect(page).to have_no_content("Text: can't be blank")
44+
end
45+
46+
# Form Submission
47+
def submit_form(name: "Spicoli", text: "dude!")
48+
fill_in "Your Name", with: name
49+
fill_in "Say something using markdown...", with: text
50+
click_button "Post"
51+
end

spec/system/shared/examples.rb

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)