Skip to content

Commit 479aa0d

Browse files
saramicBashirTowdieebrentonannancaitlinpbcameocodes
committed
Given When Then steps
Co-authored-by: Bashir Towdiee <towdiee.bashir@gmail.com> Co-authored-by: Brenton Annan <brentonannan@brentonannan.com> Co-authored-by: Caitlin Palmer-Bright <caitlin.palmer-bright@tworedkites.com> Co-authored-by: Cameo Langford <hello@cameocodes.com> Co-authored-by: Dana Scheider <dana.scheider@gmail.com> Co-authored-by: Eathan Langford <eathanlangford@gmail.com> Co-authored-by: Emily Coats <ec@emilycoats.net> Co-authored-by: Emma Park <emma.park@envato.com> Co-authored-by: Erin Belot <erinbelot@gmail.com> Co-authored-by: Geoffrey Donaldson <geoffreyd@gmail.com> Co-authored-by: Isikyus <isikyus@users.noreply.github.com> Co-authored-by: James Martelletti <james@martelletti.com.au> Co-authored-by: Jess Brown <noiselessdwindle@gmail.com> Co-authored-by: Jon Leighton <j@jonathanleighton.com> Co-authored-by: Keith Pitty <keith@keithpitty.com> Co-authored-by: Kirsten Comandich <kcomandich@gmail.com> Co-authored-by: Laurence Dibah <laurencedibah@gmail.com> Co-authored-by: Matt Patterson <matt.patterson94@gmail.com> Co-authored-by: Michael Morris <mtcmorris@gmail.com> Co-authored-by: Nadia Vu <winter.nga@gmail.com> Co-authored-by: Nick Wolf <git@nickwolf.com.au> Co-authored-by: Paul Douglas <pdouglas@ssi.org.au> Co-authored-by: Rob Jacoby <robert.jacoby@cultureamp.com> Co-authored-by: Selena Small <selenawiththetattoo@gmail.com> Co-authored-by: Sonya Corcoran <sonyacorcoran@gmail.com> Co-authored-by: Tim Lucas <t@toolmantim.com> Co-authored-by: Chris Aitchison <cmaitchison@gmail.com>
1 parent 74154c0 commit 479aa0d

File tree

7 files changed

+97
-16
lines changed

7 files changed

+97
-16
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ group :test do
5858
# Easy installation and use of chromedriver to run system tests with Chrome
5959
gem 'chromedriver-helper'
6060
gem 'rspec-rails'
61+
62+
gem 'rspec-example_steps'
63+
gem 'rspec-wait'
6164
end
6265

6366
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

Gemfile.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,14 @@ GEM
142142
rb-inotify (0.9.10)
143143
ffi (>= 0.5.0, < 2)
144144
regexp_parser (1.3.0)
145+
rspec (3.8.0)
146+
rspec-core (~> 3.8.0)
147+
rspec-expectations (~> 3.8.0)
148+
rspec-mocks (~> 3.8.0)
145149
rspec-core (3.8.0)
146150
rspec-support (~> 3.8.0)
151+
rspec-example_steps (3.0.2)
152+
rspec-core (>= 3.0.0)
147153
rspec-expectations (3.8.1)
148154
diff-lcs (>= 1.2.0, < 2.0)
149155
rspec-support (~> 3.8.0)
@@ -159,6 +165,8 @@ GEM
159165
rspec-mocks (~> 3.8.0)
160166
rspec-support (~> 3.8.0)
161167
rspec-support (3.8.0)
168+
rspec-wait (0.0.9)
169+
rspec (>= 3, < 4)
162170
ruby_dep (1.5.0)
163171
rubyzip (1.2.2)
164172
sass (3.7.2)
@@ -222,7 +230,9 @@ DEPENDENCIES
222230
pg
223231
puma (~> 3.11)
224232
rails (~> 5.2.1)
233+
rspec-example_steps
225234
rspec-rails
235+
rspec-wait
226236
sass-rails (~> 5.0)
227237
selenium-webdriver
228238
spring

client/commit

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Co-authored-by: Bashir Towdiee <towdiee.bashir@gmail.com>
2+
Co-authored-by: Brenton Annan <brentonannan@brentonannan.com>
3+
Co-authored-by: Caitlin Palmer-Bright <caitlin.palmer-bright@tworedkites.com>
4+
Co-authored-by: Cameo Langford <hello@cameocodes.com>
5+
Co-authored-by: Dana Scheider <dana.scheider@gmail.com>
6+
Co-authored-by: Eathan Langford <eathanlangford@gmail.com>
7+
Co-authored-by: Emily Coats <ec@emilycoats.net>
8+
Co-authored-by: Emma Park <emma.park@envato.com>
9+
Co-authored-by: Erin Belot <erinbelot@gmail.com>
10+
Co-authored-by: Geoffrey Donaldson <geoffreyd@gmail.com>
11+
Co-authored-by: Isikyus <isikyus@users.noreply.github.com>
12+
Co-authored-by: James Martelletti <james@martelletti.com.au>
13+
Co-authored-by: Jess Brown <noiselessdwindle@gmail.com>
14+
Co-authored-by: Jon Leighton <j@jonathanleighton.com>
15+
Co-authored-by: Keith Pitty <keith@keithpitty.com>
16+
Co-authored-by: Kirsten Comandich <kcomandich@gmail.com>
17+
Co-authored-by: Laurence Dibah <laurencedibah@gmail.com>
18+
Co-authored-by: Matt Patterson <matt.patterson94@gmail.com>
19+
Co-authored-by: Michael Morris <mtcmorris@gmail.com>
20+
Co-authored-by: Nadia Vu <winter.nga@gmail.com>
21+
Co-authored-by: Nick Wolf <git@nickwolf.com.au>
22+
Co-authored-by: Paul Douglas <pdouglas@ssi.org.au>
23+
Co-authored-by: Rob Jacoby <robert.jacoby@cultureamp.com>
24+
Co-authored-by: Selena Small <selenawiththetattoo@gmail.com>
25+
Co-authored-by: Sonya Corcoran <sonyacorcoran@gmail.com>
26+
Co-authored-by: Tim Lucas <t@toolmantim.com>
27+
Co-authored-by: Chris Aitchison <cmaitchison@gmail.com>

spec/features/games_spec.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
require 'rails_helper'
22

33
RSpec.feature "Games", type: :feature, js: true do
4-
scenario 'Visiting the game' do
5-
visit '/'
6-
expect(page).to have_content 'Welcome to the Game'
4+
scenario 'Playing the game' do
5+
When 'a user starts the game' do
6+
visit '/'
7+
expect(page).to have_content 'Welcome to the Game'
8+
page.find('[data-start-button]').click
9+
end
710

8-
page.find('[data-start-button]').click
9-
expect(page).to have_content 'This is round 1'
10-
expect(page).to have_selector('img')
11-
expect(page).to have_selector('textarea')
12-
page.find("textarea").fill_in(with: "Michael")
13-
expect(page).to_not have_content "CORRECT"
14-
expect(page).to_not have_content "NEXT"
15-
page.find("textarea").fill_in(with: "Matt")
16-
expect(page).to have_content "CORRECT"
17-
expect(page).to have_content('NEXT')
18-
page.find("[data-test-next]").click
19-
expect(page).to have_content 'This is round 2'
20-
expect(page.find("textarea").value).to eq ""
11+
Then 'the game commences' do
12+
expect(page).to have_content 'This is round 1'
13+
expect(page).to have_selector('img')
14+
expect(page).to have_selector('textarea')
15+
page.find("textarea").fill_in(with: "Michael")
16+
expect(page).to_not have_content "CORRECT"
17+
expect(page).to_not have_content "NEXT"
18+
page.find("textarea").fill_in(with: "Matt")
19+
expect(page).to have_content "CORRECT"
20+
expect(page).to have_content('NEXT')
21+
page.find("[data-test-next]").click
22+
expect(page).to have_content 'This is round 2'
23+
expect(page.find("textarea").value).to eq ""
24+
end
2125
end
2226

2327
context 'Guess name given data for Keith' do

spec/rails_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
require 'rspec/rails'
88
# Add additional requires below this line. Rails is not loaded until this point!
99

10+
Dir['spec/support/**/*.rb'].each do |file|
11+
require Rails.root.join(file).to_s
12+
end
13+
1014
# Requires supporting ruby files with custom matchers and macros, etc, in
1115
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
1216
# run as spec files by default. This means that files in spec/support that end
@@ -62,4 +66,7 @@
6266
config.filter_rails_from_backtrace!
6367
# arbitrary gems may also be filtered via:
6468
# config.filter_gems_from_backtrace("gem name")
69+
70+
# include PageFragments in features
71+
config.include PageFragments, type: :feature
6572
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module PageFragments
2+
Page = Struct.new :rspec_example do
3+
alias_method :browser, :rspec_example # Capybara DSL + rspec example context
4+
end
5+
6+
def classify(string)
7+
string.to_s.split('_').map(&:capitalize).join
8+
end
9+
10+
def focus_on(*args)
11+
require File.join(
12+
__dir__,
13+
'page_fragments',
14+
args.map(&:to_s)
15+
)
16+
mod = args.inject(PageFragments) do |klass, sub_klass|
17+
klass.const_get(classify(sub_klass))
18+
end
19+
page = Page.new(self).extend(mod)
20+
yield page if block_given?
21+
page
22+
end
23+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module PageFragments
2+
module Welcome
3+
def start_game
4+
browser.find('[data-start-button]').click
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)