diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..0f30ade --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require rails_helper diff --git a/.rubocop.yml b/.rubocop.yml index 15b7aa7..3eba727 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,3 +11,8 @@ Style/Documentation: - 'app/helpers/application_helper.rb' - 'app/mailers/application_mailer.rb' - 'app/models/application_record.rb' + - 'config/application.rb' + +Metrics/BlockLength: + Exclude: + - 'Guardfile' diff --git a/Gemfile b/Gemfile index 463c143..d0913b0 100644 --- a/Gemfile +++ b/Gemfile @@ -17,9 +17,12 @@ gem 'uglifier', '>= 1.3.0' group :development, :test do gem 'byebug', platform: :mri + gem 'factory_girl_rails' + gem 'rspec-rails' end group :development do + gem 'guard-rspec', require: false gem 'listen', '~> 3.0.5' gem 'reek', require: false gem 'rubocop', require: false @@ -28,4 +31,13 @@ group :development do gem 'web-console', '>= 3.3.0' end +group :test do + gem 'capybara' + gem 'database_cleaner' + gem 'faker' + gem 'launchy' + gem 'selenium-webdriver' + gem 'shoulda-matchers' +end + gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 99f34e7..58bb984 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,8 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) arel (7.1.4) ast (2.3.0) axiom-types (0.1.1) @@ -46,8 +48,18 @@ GEM thread_safe (~> 0.3, >= 0.3.1) builder (3.2.3) byebug (9.0.6) + capybara (2.11.0) + addressable + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + childprocess (0.5.9) + ffi (~> 1.0, >= 1.0.11) codeclimate-engine-rb (0.4.0) virtus (~> 1.0) + coderay (1.1.1) coercible (1.0.0) descendants_tracker (~> 0.0.1) coffee-rails (4.2.1) @@ -58,15 +70,39 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.0.4) + database_cleaner (1.5.3) debug_inspector (0.0.2) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.3) equalizer (0.0.11) erubis (2.7.0) execjs (2.7.0) + factory_girl (4.8.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) + railties (>= 3.0.0) + faker (1.7.2) + i18n (~> 0.5) ffi (1.9.17) + formatador (0.2.5) globalid (0.3.7) activesupport (>= 4.1.0) + guard (2.14.0) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (~> 1.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) i18n (0.7.0) ice_nine (0.11.2) jbuilder (2.6.1) @@ -76,11 +112,14 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + launchy (2.4.3) + addressable (~> 2.3) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) loofah (2.0.3) nokogiri (>= 1.5.9) + lumberjack (1.0.11) mail (2.6.4) mime-types (>= 1.16, < 4) method_source (0.8.2) @@ -90,13 +129,22 @@ GEM mini_portile2 (2.1.0) minitest (5.10.1) multi_json (1.12.1) + nenv (0.3.0) nio4r (1.2.1) nokogiri (1.7.0.1) mini_portile2 (~> 2.1.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) parser (2.3.3.1) ast (~> 2.2) pg (0.19.0) powerpack (0.1.1) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + public_suffix (2.0.5) puma (3.6.2) rack (2.0.1) rack-test (0.6.3) @@ -133,6 +181,27 @@ GEM codeclimate-engine-rb (~> 0.4.0) parser (~> 2.3.1, >= 2.3.1.2) rainbow (~> 2.0) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-rails (3.5.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) rubocop (0.47.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) @@ -140,6 +209,7 @@ GEM ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) + rubyzip (1.2.0) sass (3.4.23) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -147,6 +217,14 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + selenium-webdriver (3.0.5) + childprocess (~> 0.5) + rubyzip (~> 1.0) + websocket (~> 1.0) + shellany (0.0.1) + shoulda-matchers (3.1.1) + activesupport (>= 4.0.0) + slop (3.6.0) spring (2.0.1) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -180,25 +258,37 @@ GEM activemodel (>= 5.0) debug_inspector railties (>= 5.0) + websocket (1.2.3) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES byebug + capybara coffee-rails (~> 4.2) + database_cleaner + factory_girl_rails + faker + guard-rspec jbuilder (~> 2.5) jquery-rails + launchy listen (~> 3.0.5) pg (~> 0.18) puma (~> 3.0) rails (~> 5.0.1) reek + rspec-rails rubocop sass-rails (~> 5.0) + selenium-webdriver + shoulda-matchers spring spring-watcher-listen (~> 2.0.0) turbolinks (~> 5) diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..154bd18 --- /dev/null +++ b/Guardfile @@ -0,0 +1,70 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +# Note: The cmd option is now required due to the increasing number of ways +# rspec may be run, below are examples of the most common uses. +# * bundler: 'bundle exec rspec' +# * bundler binstubs: 'bin/rspec' +# * spring: 'bin/rspec' (This will use spring if running and you have +# installed the spring binstubs per the docs) +# * zeus: 'zeus rspec' (requires the server to be started separately) +# * 'just' rspec: 'rspec' + +guard :rspec, cmd: 'bundle exec rspec' do + require 'guard/rspec/dsl' + dsl = Guard::RSpec::Dsl.new(self) + + # Feel free to open issues for suggestions and improvements + + # RSpec files + rspec = dsl.rspec + watch(rspec.spec_helper) { rspec.spec_dir } + watch(rspec.spec_support) { rspec.spec_dir } + watch(rspec.spec_files) + + # Ruby files + ruby = dsl.ruby + dsl.watch_spec_files_for(ruby.lib_files) + + # Rails files + rails = dsl.rails(view_extensions: %w(erb haml slim)) + dsl.watch_spec_files_for(rails.app_files) + dsl.watch_spec_files_for(rails.views) + + watch(rails.controllers) do |m| + [ + rspec.spec.call("routing/#{m[1]}_routing"), + rspec.spec.call("controllers/#{m[1]}_controller"), + rspec.spec.call("acceptance/#{m[1]}") + ] + end + + # Rails config changes + watch(rails.spec_helper) { rspec.spec_dir } + watch(rails.routes) { "#{rspec.spec_dir}/routing" } + watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } + + # Capybara features specs + watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } + watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| + Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' + end +end diff --git a/config/application.rb b/config/application.rb index a84a8b7..2c18fd8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,8 +18,15 @@ module Room538 class Application < Rails::Application - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. + config.generators do |generator| + generator.test_framework :rspec, + fixtures: true, + view_specs: false, + helper_specs: false, + routing_specs: false, + controller_specs: true, + request_specs: false + generator.fixture_replacement :factory_girl, dir: 'spec/factories' + end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..6df5679 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,21 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) + +# Prevent database truncation if the environment is production +abort('The Rails environment is running in production mode!') if Rails.env.production? +require 'spec_helper' +require 'rspec/rails' + +# Add additional requires below this line. Rails is not loaded until this point! + +Dir[Rails.root.join('spec', 'support**', '*.rb')].each { |f| require f } + +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + config.use_transactional_fixtures = false + + config.infer_spec_type_from_file_location! + + config.filter_rails_from_backtrace! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d7ddffd --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,26 @@ +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + config.shared_context_metadata_behavior = :apply_to_host_groups + + config.filter_run_when_matching :focus + + config.disable_monkey_patching! + + config.default_formatter = 'doc' if config.files_to_run.one? + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + # config.profile_examples = 10 + + config.order = :random + + Kernel.srand config.seed +end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 0000000..e0dbc9a --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,21 @@ +RSpec.configure do |config| + config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner.strategy = :transaction + end + + config.before(:each, js: true) do + DatabaseCleaner.strategy = :truncation + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + end +end diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb new file mode 100644 index 0000000..eec437f --- /dev/null +++ b/spec/support/factory_girl.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods +end diff --git a/spec/support/shoulda_matchers.rb b/spec/support/shoulda_matchers.rb new file mode 100644 index 0000000..7d045f3 --- /dev/null +++ b/spec/support/shoulda_matchers.rb @@ -0,0 +1,6 @@ +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end