|
8 | 8 | let(:name) { "John Smith" } |
9 | 9 | let(:text) { "Hello there!" } |
10 | 10 |
|
11 | | - include_context "Form Submitted", name: :name, text: :text |
| 11 | + submit_form(name: :name, text: :text) |
12 | 12 |
|
13 | 13 | scenario "when comment is added" do |
14 | 14 | expect(page).to have_css(".js-comment-author", text: name) |
|
36 | 36 | context "with iframe text" do |
37 | 37 | let(:iframe_text) { '<iframe src="http://www.w3schools.com"></iframe>' } |
38 | 38 |
|
39 | | - include_context "Form Submitted", text: :iframe_text |
| 39 | + submit_form(name: "", text: :iframe_text) |
40 | 40 |
|
41 | 41 | scenario "doesn't add an iframe" do |
42 | 42 | expect(page).not_to have_css("iframe") |
43 | 43 | end |
44 | 44 | end |
45 | 45 | end |
46 | 46 |
|
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") |
53 | 51 |
|
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" |
59 | 57 |
|
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") |
65 | 61 | end |
66 | 62 |
|
67 | 63 | # Forms |
68 | | -shared_examples "with Inline Form" do |
| 64 | +def select_inline_form(page) |
69 | 65 | click_link "Inline Form" |
70 | 66 | expect(page).to have_css("form.commentForm.form-inline") |
71 | 67 | end |
72 | | -shared_examples "with Stacked Form" do |
| 68 | +def select_stacked_form(page) |
73 | 69 | click_link "Stacked Form" |
74 | 70 | expect(page).to have_css("form.commentForm.form-stacked") |
75 | 71 | 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) |
78 | 74 | click_link "Horizontal Form" |
79 | 75 | expect(page).to have_css("form.commentForm.form-horizontal") |
80 | 76 | end |
81 | 77 |
|
82 | 78 | # Form Submission |
83 | | -shared_examples "when Form Submitted", form_submitted: true do |name: "Spicoli", text: "dude!"| |
| 79 | +def submit_form(name: "Spicoli", text: "dude!") |
84 | 80 | fill_in "Your Name", with: name |
85 | 81 | fill_in "Say something using markdown...", with: text |
86 | 82 | click_button "Post" |
87 | 83 | end |
88 | 84 |
|
89 | | -shared_examples "when Form Submitted with Blank Fields", blank_form_submitted: true do |
90 | | - include_context "Form Submitted", name: "", text: "" |
91 | | -end |
92 | | - |
93 | 85 | shared_examples "when from classic page" do |
94 | 86 | click_link "New Comment" |
95 | 87 |
|
|
0 commit comments