Skip to content

Commit 80ed241

Browse files
committed
Switch to RSpec's implicit shared context via metadata
1 parent 7c1ce1f commit 80ed241

File tree

5 files changed

+24
-40
lines changed

5 files changed

+24
-40
lines changed

spec/features/add_new_comment_spec.rb

+9-18
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,31 @@
33
require "features/shared/contexts"
44

55
feature "Add new comment" do
6-
context "from main page", js: true do
7-
include_context "Main Page"
8-
context "via Horizontal Form" do
9-
include_context "Horizontal Form"
6+
context "from main page", page: :main, js: true do
7+
context "via Horizontal Form", form: :horizontal do
108
include_examples "New Comment Submission"
119
end
12-
context "via Inline Form" do
13-
include_context "Inline Form"
10+
context "via Inline Form", form: :inline do
1411
include_examples "New Comment Submission"
1512
end
16-
context "via Stacked Form" do
17-
include_context "Stacked Form"
13+
context "via Stacked Form", form: :stacked do
1814
include_examples "New Comment Submission"
1915
end
2016
end
2117

22-
context "from simple page", js: true do
23-
include_context "Simple Page"
24-
context "via Horizontal Form" do
25-
include_context "Horizontal Form"
18+
context "from simple page", page: :simple, js: true do
19+
context "via Horizontal Form", form: :horizontal do
2620
include_examples "New Comment Submission"
2721
end
28-
context "via Inline Form" do
29-
include_context "Inline Form"
22+
context "via Inline Form", form: :inline do
3023
include_examples "New Comment Submission"
3124
end
32-
context "via the Stacked Form" do
33-
include_context "Stacked Form"
25+
context "via the Stacked Form", form: :stacked do
3426
include_examples "New Comment Submission"
3527
end
3628
end
3729

38-
context "from classic page" do
39-
include_context "Classic Page"
30+
context "from classic page", page: :classic do
4031
background { click_link "New Comment" }
4132
include_examples "New Comment Submission"
4233
end

spec/features/destroy_comment_spec.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
require "rails_helper"
22
require "features/shared/contexts"
33

4-
feature "Destroy a comment" do
5-
include_context "Existing Comment"
6-
context "from classic page" do
7-
include_context "Classic Page"
4+
feature "Destroy a comment", existing_comment: true do
5+
context "from classic page", page: :classic do
86
let(:comment) { Comment.first }
97

108
scenario "clicking destroy link destroys comment" do

spec/features/edit_comment_spec.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
require "features/shared/examples"
33
require "features/shared/contexts"
44

5-
feature "Edit a comment" do
6-
include_context "Existing Comment"
5+
feature "Edit a comment", existing_comment: true do
76
let(:comment) { Comment.first }
87

9-
context "from classic page" do
10-
include_context "Classic Page"
8+
context "from classic page", page: :classic do
119
background { click_link "Edit", match: :first }
1210

1311
context "when edit is submitted" do
@@ -20,9 +18,7 @@
2018
end
2119
end
2220

23-
context "when edit is submitted with blank fields" do
24-
include_context "Form Submitted with Blank Fields"
25-
21+
context "when edit is submitted with blank fields", blank_form_submitted: true do
2622
scenario "comment is not updated" do
2723
expect(page).not_to have_success_message
2824
expect(page).to have_failure_message

spec/features/shared/contexts.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
require "rails_helper"
22

33
# Pages
4-
shared_context "Main Page" do
4+
shared_context "Main Page", page: :main do
55
background { visit root_path }
66
end
7-
shared_context "Simple Page" do
7+
shared_context "Simple Page", page: :simple do
88
background { visit simple_path }
99
end
10-
shared_context "Classic Page" do
10+
shared_context "Classic Page", page: :classic do
1111
background { visit comments_path }
1212
end
1313

1414
# Forms
15-
shared_context "Horizontal Form" do
15+
shared_context "Horizontal Form", form: :horizontal do
1616
background { click_link "Horizontal Form" }
1717
end
18-
shared_context "Inline Form" do
18+
shared_context "Inline Form", form: :inline do
1919
background { click_link "Inline Form" }
2020
end
21-
shared_context "Stacked Form" do
21+
shared_context "Stacked Form", form: :stacked do
2222
background { click_link "Stacked Form" }
2323
end
2424

2525
# Form Submission
26-
shared_context "Form Submitted" do |name: "Spicoli", text: "dude!"|
26+
shared_context "Form Submitted", form_submitted: true do |name: "Spicoli", text: "dude!"|
2727
let(:hint_name) { "Your Name" }
2828
let(:hint_text) { "Say something using markdown..." }
2929
let(:name) { name }
@@ -36,11 +36,11 @@
3636
end
3737
end
3838

39-
shared_context "Form Submitted with Blank Fields" do
39+
shared_context "Form Submitted with Blank Fields", blank_form_submitted: true do
4040
include_context "Form Submitted", name: "", text: ""
4141
end
4242

4343
# Fixtures
44-
shared_context "Existing Comment" do
44+
shared_context "Existing Comment", existing_comment: true do
4545
before { Comment.create(author: "John Doe", text: "Hello there!") }
4646
end

spec/features/shared/examples.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
end
1414
end
1515

16-
context "when the new comment is submmited with blank fields" do
16+
context "when the new comment is submmited with blank fields", blank_form_submitted: true do
1717
let!(:comments_count) { all(".comment").size }
18-
include_context "Form Submitted with Blank Fields"
1918

2019
scenario "comment is not added" do
2120
expect(page).to have_selector(".comment", count: comments_count)

0 commit comments

Comments
 (0)