Skip to content

Commit 94fc210

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

File tree

5 files changed

+90
-139
lines changed

5 files changed

+90
-139
lines changed

spec/system/add_new_comment_spec.rb

Lines changed: 48 additions & 37 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
9-
context "with Horizontal Form" do
10-
include_examples "with Horizontal Form"
11-
include_examples "New Comment Submission", true
12-
include_examples "Validation errors displaying"
8+
it "with Horizontal Form" do
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

15-
context "with Inline Form" do
16-
include_examples "with Inline Form"
17-
include_examples "New Comment Submission", true
18-
include_examples "Validation errors displaying"
16+
it "with Inline Form" do
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

21-
context "with Stacked Form" do
22-
include_examples "with Stacked Form"
23-
include_examples "New Comment Submission", true
24-
include_examples "Validation errors displaying"
23+
it "with Stacked Form" do
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
29-
context "with Horizontal Form" do
30-
include_examples "with Horizontal Form"
31-
include_examples "New Comment Submission", true
32-
include_examples "Validation errors displaying"
32+
it "with Horizontal Form" do
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

35-
context "with Inline Form" do
36-
include_examples "with Inline Form"
37-
include_examples "New Comment Submission", true
38-
include_examples "Validation errors displaying"
40+
it "with Inline Form" do
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

41-
context "with Stacked Form" do
42-
include_examples "with Stacked Form"
43-
include_examples "New Comment Submission", true
44-
include_examples "Validation errors displaying"
47+
it "with Stacked Form" do
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
49-
context "with Horizontal Form" do
50-
include_examples "with Horizontal Form"
51-
include_examples "New Comment Submission", false
52-
include_examples "Validation errors displaying"
56+
it "with Horizontal Form" do
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

55-
context "with Inline Form" do
56-
include_examples "with Inline Form"
57-
include_examples "New Comment Submission", false
58-
include_examples "Validation errors displaying"
64+
it "with Inline Form" do
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

61-
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"
71+
it "with the Stacked Form" do
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
# frozen_string_literal: true
22

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

76
describe "Edit a comment", existing_comment: true do
87
let(:comment) { Comment.first }
98

109
context "when from classic page" do
1110
it "comment is updated when edit is submitted" do
12-
include_examples "when from classic page"
11+
click_link "New Comment"
12+
submit_form
13+
1314
click_link "Edit", match: :first
1415
let(:edited_name) { "Abraham Lincoln" }
1516

16-
include_context "when Form Submitted", name: :edited_name
17+
subit_form(name: :edited_name)
1718
expect(page).to have_css(".comment", text: :edited_name)
1819
expect(page).to have_css("#notice", text: "Comment was successfully updated.")
1920
end
2021

2122
it "comment is not updated when edit is submitted with blank fields", blank_form_submitted: true do
22-
include_examples "when from classic page"
23+
click_link "New Comment"
24+
submit_form
25+
2326
click_link "Edit", match: :first
27+
submit_form(name: "", text: "")
28+
2429
expect(page).not_to have_success_message
2530
expect(page).to have_failure_message
2631
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)