Skip to content

Commit 9245d1b

Browse files
committed
Configure for rspec test, comments feature test
1 parent 3870cee commit 9245d1b

File tree

10 files changed

+236
-17
lines changed

10 files changed

+236
-17
lines changed

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--color
2+
--require spec_helper
3+
--format documentation

Gemfile

+7-4
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ group :development, :test do
5555

5656
# Manage application processes
5757
gem 'foreman'
58-
end
5958

60-
group :test, :development do
6159
gem 'rspec-rails'
6260
gem 'factory_girl_rails'
61+
end
62+
63+
group :test do
6364
gem 'capybara'
64-
gem 'capybara-webkit'
65+
#gem 'capybara-webkit'
6566
gem 'capybara-screenshot'
66-
gem 'rspec-instafail', require: false
67+
gem 'database_cleaner'
68+
gem 'launchy'
69+
gem 'selenium-webdriver'
6770
end

Gemfile.lock

+14-11
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ GEM
6060
capybara-screenshot (1.0.7)
6161
capybara (>= 1.0, < 3)
6262
launchy
63-
capybara-webkit (1.4.1)
64-
capybara (>= 2.3.0, < 2.5.0)
65-
json
63+
childprocess (0.5.5)
64+
ffi (~> 1.0, >= 1.0.11)
6665
coffee-rails (4.1.0)
6766
coffee-script (>= 2.2.0)
6867
railties (>= 4.0.0, < 5.0)
@@ -71,6 +70,7 @@ GEM
7170
execjs
7271
coffee-script-source (1.9.0)
7372
columnize (0.9.0)
73+
database_cleaner (1.4.1)
7474
debug_inspector (0.0.2)
7575
debugger-linecache (1.2.0)
7676
diff-lcs (1.2.5)
@@ -82,6 +82,7 @@ GEM
8282
factory_girl_rails (4.5.0)
8383
factory_girl (~> 4.5.0)
8484
railties (>= 3.0.0)
85+
ffi (1.9.8)
8586
foreman (0.77.0)
8687
dotenv (~> 1.0.2)
8788
thor (~> 0.19.1)
@@ -147,17 +148,11 @@ GEM
147148
rake (10.4.2)
148149
rdoc (4.2.0)
149150
json (~> 1.4)
150-
rspec (3.2.0)
151-
rspec-core (~> 3.2.0)
152-
rspec-expectations (~> 3.2.0)
153-
rspec-mocks (~> 3.2.0)
154151
rspec-core (3.2.2)
155152
rspec-support (~> 3.2.0)
156153
rspec-expectations (3.2.0)
157154
diff-lcs (>= 1.2.0, < 2.0)
158155
rspec-support (~> 3.2.0)
159-
rspec-instafail (0.2.6)
160-
rspec
161156
rspec-mocks (3.2.1)
162157
diff-lcs (>= 1.2.0, < 2.0)
163158
rspec-support (~> 3.2.0)
@@ -170,6 +165,7 @@ GEM
170165
rspec-mocks (~> 3.2.0)
171166
rspec-support (~> 3.2.0)
172167
rspec-support (3.2.2)
168+
rubyzip (1.1.7)
173169
sass (3.4.11)
174170
sass-rails (5.0.1)
175171
railties (>= 4.0.0, < 5.0)
@@ -180,6 +176,11 @@ GEM
180176
sdoc (0.4.1)
181177
json (~> 1.7, >= 1.7.7)
182178
rdoc (~> 4.0)
179+
selenium-webdriver (2.45.0)
180+
childprocess (~> 0.5)
181+
multi_json (~> 1.0)
182+
rubyzip (~> 1.0)
183+
websocket (~> 1.0)
183184
slop (3.6.0)
184185
spring (1.2.0)
185186
sprockets (2.12.3)
@@ -211,6 +212,7 @@ GEM
211212
binding_of_caller (>= 0.7.2)
212213
railties (~> 4.0)
213214
sprockets-rails (>= 2.0, < 4.0)
215+
websocket (1.2.1)
214216
xpath (2.0.0)
215217
nokogiri (~> 1.3)
216218

@@ -223,20 +225,21 @@ DEPENDENCIES
223225
byebug
224226
capybara
225227
capybara-screenshot
226-
capybara-webkit
227228
coffee-rails
229+
database_cleaner
228230
factory_girl_rails
229231
foreman
230232
jbuilder
231233
jquery-rails
234+
launchy
232235
pg
233236
rails (~> 4.2)
234237
rails-html-sanitizer
235238
rails_12factor
236-
rspec-instafail
237239
rspec-rails
238240
sass-rails
239241
sdoc
242+
selenium-webdriver
240243
spring
241244
sqlite3
242245
turbolinks

bin/rspec

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# This file was generated by Bundler.
4+
#
5+
# The application 'rspec' is installed as part of a gem, and
6+
# this file is here to facilitate running it.
7+
#
8+
9+
require 'pathname'
10+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11+
Pathname.new(__FILE__).realpath)
12+
13+
require 'rubygems'
14+
require 'bundler/setup'
15+
16+
load Gem.bin_path('rspec-core', 'rspec')

config/environments/production.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# config.action_dispatch.rack_cache = true
2121

2222
# Disable Rails's static asset server (Apache or NGINX will already do this).
23-
config.serve_static_assets = false
23+
config.serve_static_files = false
2424

2525
# Compress JavaScripts and CSS.
2626
config.assets.js_compressor = :uglifier

config/environments/test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
config.eager_load = false
1414

1515
# Configure static asset server for tests with Cache-Control for performance.
16-
config.serve_static_assets = true
16+
config.serve_static_files = true
1717
config.static_cache_control = 'public, max-age=3600'
1818

1919
# Show full error reports and disable caching.

spec/features/comments_spec.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'rails_helper'
2+
3+
feature 'Add new comment' do
4+
scenario 'selects horizontal form', js: true do
5+
visit root_path
6+
click_link 'Horizontal Form'
7+
fill_in 'Your Name', with: 'Tommy'
8+
fill_in 'Say something...', with: "Surf's up dude!"
9+
click_button 'Post'
10+
expect(page).to have_text('Tommy')
11+
expect(page).to have_text("Surf's up dude!")
12+
#expect(page).to have_selector('div.commentAuthor foobar', :text => 'Tommy')
13+
#expect(find('#commentList').find('h2')).to have_content('Tommy')
14+
#expect(find('#commentList').find('span')).to have_content("Surf's up dude!")
15+
end
16+
17+
scenario 'selects stacked form', js: true do
18+
visit root_path
19+
click_link 'Stacked Form'
20+
fill_in 'Your Name', with: 'Spicoli'
21+
fill_in 'Say something...', with: 'Cowabunga dude!'
22+
click_button 'Post'
23+
expect(page).to have_text('Spicoli')
24+
expect(page).to have_text('Cowabunga dude!')
25+
end
26+
27+
scenario 'selects inline form', js: true do
28+
visit root_path
29+
click_link 'Inline Form'
30+
fill_in 'Your Name', with: 'Wilbur Kookmeyer'
31+
fill_in 'Say something...', with: 'dude!'
32+
click_button 'Post'
33+
expect(page).to have_text('Wilbur Kookmeyer')
34+
expect(page).to have_text('dude!')
35+
end
36+
37+
38+
39+
end
40+
41+

spec/rails_helper.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This file is copied to spec/ when you run 'rails generate rspec:install'
2+
ENV['RAILS_ENV'] ||= 'test'
3+
require 'spec_helper'
4+
require File.expand_path('../../config/environment', __FILE__)
5+
require 'rspec/rails'
6+
require 'capybara/rspec'
7+
# Add additional requires below this line. Rails is not loaded until this point!
8+
9+
# Requires supporting ruby files with custom matchers and macros, etc, in
10+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
11+
# run as spec files by default. This means that files in spec/support that end
12+
# in _spec.rb will both be required and run as specs, causing the specs to be
13+
# run twice. It is recommended that you do not name files matching this glob to
14+
# end with _spec.rb. You can configure this pattern with the --pattern
15+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
16+
#
17+
# The following line is provided for convenience purposes. It has the downside
18+
# of increasing the boot-up time by auto-requiring all files in the support
19+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
20+
# require only the support files necessary.
21+
#
22+
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
23+
24+
# Checks for pending migrations before tests are run.
25+
# If you are not using ActiveRecord, you can remove this line.
26+
ActiveRecord::Migration.maintain_test_schema!
27+
28+
RSpec.configure do |config|
29+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
30+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
31+
32+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
33+
# examples within a transaction, remove the following line or assign false
34+
# instead of true.
35+
config.use_transactional_fixtures = true
36+
37+
# RSpec Rails can automatically mix in different behaviours to your tests
38+
# based on their file location, for example enabling you to call `get` and
39+
# `post` in specs under `spec/controllers`.
40+
#
41+
# You can disable this behaviour by removing the line below, and instead
42+
# explicitly tag your specs with their type, e.g.:
43+
#
44+
# RSpec.describe UsersController, :type => :controller do
45+
# # ...
46+
# end
47+
#
48+
# The different available types are documented in the features, such as in
49+
# https://relishapp.com/rspec/rspec-rails/docs
50+
config.infer_spec_type_from_file_location!
51+
end

spec/spec_helper.rb

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
2+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3+
# The generated `.rspec` file contains `--require spec_helper` which will cause
4+
# this file to always be loaded, without a need to explicitly require it in any
5+
# files.
6+
#
7+
# Given that it is always loaded, you are encouraged to keep this file as
8+
# light-weight as possible. Requiring heavyweight dependencies from this file
9+
# will add to the boot time of your test suite on EVERY test run, even for an
10+
# individual file that may not need all of that loaded. Instead, consider making
11+
# a separate helper file that requires the additional dependencies and performs
12+
# the additional setup, and require it from the spec files that actually need
13+
# it.
14+
#
15+
# The `.rspec` file also contains a few flags that are not defaults but that
16+
# users commonly want.
17+
#
18+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19+
RSpec.configure do |config|
20+
# rspec-expectations config goes here. You can use an alternate
21+
# assertion/expectation library such as wrong or the stdlib/minitest
22+
# assertions if you prefer.
23+
config.expect_with :rspec do |expectations|
24+
# This option will default to `true` in RSpec 4. It makes the `description`
25+
# and `failure_message` of custom matchers include text for helper methods
26+
# defined using `chain`, e.g.:
27+
# be_bigger_than(2).and_smaller_than(4).description
28+
# # => "be bigger than 2 and smaller than 4"
29+
# ...rather than:
30+
# # => "be bigger than 2"
31+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32+
end
33+
34+
# rspec-mocks config goes here. You can use an alternate test double
35+
# library (such as bogus or mocha) by changing the `mock_with` option here.
36+
config.mock_with :rspec do |mocks|
37+
# Prevents you from mocking or stubbing a method that does not exist on
38+
# a real object. This is generally recommended, and will default to
39+
# `true` in RSpec 4.
40+
mocks.verify_partial_doubles = true
41+
end
42+
43+
# The settings below are suggested to provide a good initial experience
44+
# with RSpec, but feel free to customize to your heart's content.
45+
=begin
46+
# These two settings work together to allow you to limit a spec run
47+
# to individual examples or groups you care about by tagging them with
48+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
49+
# get run.
50+
config.filter_run :focus
51+
config.run_all_when_everything_filtered = true
52+
53+
# Limits the available syntax to the non-monkey patched syntax that is
54+
# recommended. For more details, see:
55+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58+
config.disable_monkey_patching!
59+
60+
# Many RSpec users commonly either run the entire suite or an individual
61+
# file, and it's useful to allow more verbose output when running an
62+
# individual spec file.
63+
if config.files_to_run.one?
64+
# Use the documentation formatter for detailed output,
65+
# unless a formatter has already been configured
66+
# (e.g. via a command-line flag).
67+
config.default_formatter = 'doc'
68+
end
69+
70+
# Print the 10 slowest examples and example groups at the
71+
# end of the spec run, to help surface which specs are running
72+
# particularly slow.
73+
config.profile_examples = 10
74+
75+
# Run specs in random order to surface order dependencies. If you find an
76+
# order dependency and want to debug it, you can fix the order by providing
77+
# the seed, which is printed after each run.
78+
# --seed 1234
79+
config.order = :random
80+
81+
# Seed global randomization in this process using the `--seed` CLI option.
82+
# Setting this allows you to use `--seed` to deterministically reproduce
83+
# test failures related to randomization by passing the same `--seed` value
84+
# as the one that triggered the failure.
85+
Kernel.srand config.seed
86+
=end
87+
end

spec/support/capybara.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'selenium-webdriver'
2+
3+
Capybara.register_driver :selenium_chrome do |app|
4+
Capybara::Selenium::Driver.new(app, :browser => :chrome)
5+
end
6+
7+
# Saves page to place specfied at
8+
# NOTE: you must pass js: true for the feature definition (or else you'll see that render doesn't exist!)
9+
# call force = true, or set ENV[RENDER_SCREENSHOTS] == 'YES'
10+
def render_page(name, force = false)
11+
if force || (ENV['RENDER_SCREENSHOTS'] == 'YES')
12+
path = File.join Rails.application.config.integration_test_render_dir, "#{name}.png"
13+
page.driver.render(path)
14+
end
15+
end

0 commit comments

Comments
 (0)