Skip to content

Commit 3bd09ff

Browse files
committed
rails_apps_composer: testing framework
1 parent bd26d95 commit 3bd09ff

File tree

14 files changed

+269
-10
lines changed

14 files changed

+269
-10
lines changed

Guardfile

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
## Uncomment and set this to only include directories you want to watch
5+
# directories %w(app lib config test spec feature)
6+
7+
## Uncomment to clear the screen before every task
8+
# clearing :on
9+
10+
## Guard internally checks for changes in the Guardfile and exits.
11+
## If you want Guard to automatically start up again, run guard in a
12+
## shell loop, e.g.:
13+
##
14+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
15+
##
16+
## Note: if you are using the `directories` clause above and you are not
17+
## watching the project directory ('.'), the you will want to move the Guardfile
18+
## to a watched dir and symlink it back, e.g.
19+
#
20+
# $ mkdir config
21+
# $ mv Guardfile config/
22+
# $ ln -s config/Guardfile .
23+
#
24+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25+
26+
guard :bundler do
27+
require 'guard/bundler'
28+
require 'guard/bundler/verify'
29+
helper = Guard::Bundler::Verify.new
30+
31+
files = ['Gemfile']
32+
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
33+
34+
# Assume files are symlinked from somewhere
35+
files.each { |file| watch(helper.real_path(file)) }
36+
end
37+
38+
guard 'rails' do
39+
watch('Gemfile.lock')
40+
watch(%r{^(config|lib)/.*})
41+
end
42+
43+
44+
# Note: The cmd option is now required due to the increasing number of ways
45+
# rspec may be run, below are examples of the most common uses.
46+
# * bundler: 'bundle exec rspec'
47+
# * bundler binstubs: 'bin/rspec'
48+
# * spring: 'bin/rspec' (This will use spring if running and you have
49+
# installed the spring binstubs per the docs)
50+
# * zeus: 'zeus rspec' (requires the server to be started separately)
51+
# * 'just' rspec: 'rspec'
52+
53+
guard :rspec, cmd: "bundle exec rspec" do
54+
require "guard/rspec/dsl"
55+
dsl = Guard::RSpec::Dsl.new(self)
56+
57+
# Feel free to open issues for suggestions and improvements
58+
59+
# RSpec files
60+
rspec = dsl.rspec
61+
watch(rspec.spec_helper) { rspec.spec_dir }
62+
watch(rspec.spec_support) { rspec.spec_dir }
63+
watch(rspec.spec_files)
64+
65+
# Ruby files
66+
ruby = dsl.ruby
67+
dsl.watch_spec_files_for(ruby.lib_files)
68+
69+
# Rails files
70+
rails = dsl.rails(view_extensions: %w(erb haml slim))
71+
dsl.watch_spec_files_for(rails.app_files)
72+
dsl.watch_spec_files_for(rails.views)
73+
74+
watch(rails.controllers) do |m|
75+
[
76+
rspec.spec.("routing/#{m[1]}_routing"),
77+
rspec.spec.("controllers/#{m[1]}_controller"),
78+
rspec.spec.("acceptance/#{m[1]}")
79+
]
80+
end
81+
82+
# Rails config changes
83+
watch(rails.spec_helper) { rspec.spec_dir }
84+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
85+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
86+
87+
# Capybara features specs
88+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
89+
90+
# Turnip features and steps
91+
watch(%r{^spec/acceptance/(.+)\.feature$})
92+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
93+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
94+
end
95+
end

config/application.rb

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88

99
module MemberfulExample
1010
class Application < Rails::Application
11+
12+
config.generators do |g|
13+
g.test_framework :rspec,
14+
fixtures: true,
15+
view_specs: false,
16+
helper_specs: false,
17+
routing_specs: false,
18+
controller_specs: false,
19+
request_specs: false
20+
g.fixture_replacement :factory_girl, dir: "spec/factories"
21+
end
22+
1123
# Settings in config/environments/* take precedence over those specified here.
1224
# Application configuration should go into files in config/initializers
1325
# -- all .rb files in that directory are automatically loaded.

spec/rails_helper.rb

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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Capybara.asset_host = 'http://localhost:3000'

spec/support/database_cleaner.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
RSpec.configure do |config|
2+
config.before(:suite) do
3+
DatabaseCleaner.clean_with(:truncation)
4+
end
5+
6+
config.before(:each) do
7+
DatabaseCleaner.strategy = :transaction
8+
end
9+
10+
config.before(:each, :js => true) do
11+
DatabaseCleaner.strategy = :truncation
12+
end
13+
14+
config.before(:each) do
15+
DatabaseCleaner.start
16+
end
17+
18+
config.append_after(:each) do
19+
DatabaseCleaner.clean
20+
end
21+
end

spec/support/factory_girl.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RSpec.configure do |config|
2+
config.include FactoryGirl::Syntax::Methods
3+
end

test/controllers/.keep

Whitespace-only changes.

test/fixtures/.keep

Whitespace-only changes.

test/helpers/.keep

Whitespace-only changes.

test/integration/.keep

Whitespace-only changes.

test/mailers/.keep

Whitespace-only changes.

test/models/.keep

Whitespace-only changes.

test/test_helper.rb

-10
This file was deleted.

0 commit comments

Comments
 (0)