diff --git a/.gitignore b/.gitignore index 1f31f8a..64b868d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ /db/*.sqlite3 /db/*.sqlite3-journal +# Ignore rspec examples file +/spec/examples.txt + # Ignore all logfiles and tempfiles. /log/* !/log/.keep diff --git a/spec/features/home_page_spec.rb b/spec/features/home_page_spec.rb index 3f482b6..515ebe9 100644 --- a/spec/features/home_page_spec.rb +++ b/spec/features/home_page_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "Home page" do +RSpec.describe "Home page" do scenario "visit" do visit "/" diff --git a/spec/features/share_page_spec.rb b/spec/features/share_page_spec.rb index c2436df..f383e93 100644 --- a/spec/features/share_page_spec.rb +++ b/spec/features/share_page_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "Share page", js: true do +RSpec.describe "Share page", js: true do scenario "displays 3rd party widgets" do visit "/share" diff --git a/spec/features/subscribe_to_newsletter_spec.rb b/spec/features/subscribe_to_newsletter_spec.rb index 47fff0e..dcfd618 100644 --- a/spec/features/subscribe_to_newsletter_spec.rb +++ b/spec/features/subscribe_to_newsletter_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "Subscribe to newsletter" do +RSpec.describe "Subscribe to newsletter" do context "in browser with native date input", driver: driver_with(native_date_input: true) do diff --git a/spec/features/user_login_and_logout_spec.rb b/spec/features/user_login_and_logout_spec.rb index f811122..f864fa6 100644 --- a/spec/features/user_login_and_logout_spec.rb +++ b/spec/features/user_login_and_logout_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "User logs in and logs out" do +RSpec.describe "User logs in and logs out" do # `js: true` spec metadata means this will run using the `:selenium` # browser driver configured in spec/support/capybara.rb @@ -51,8 +51,8 @@ login email, "1st-try-wrong-password" expect(page).to have_content "Invalid email or password" - - login email, "2nd-try-wrong-password" + + login email, "2nd-try-wrong-password" expect(page).to have_content "You have one more attempt before your account is locked" login email, "3rd-try-wrong-password" diff --git a/spec/features/user_registers_spec.rb b/spec/features/user_registers_spec.rb index f9a303c..6819b0c 100644 --- a/spec/features/user_registers_spec.rb +++ b/spec/features/user_registers_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "User registers" do +RSpec.describe "User registers" do scenario "with valid details" do @@ -85,7 +85,7 @@ end scenario "too short password" do - + min_password_length = 8 too_short_password = "p" * (min_password_length - 1) fill_in "Email", with: "someone@example.tld" diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index eb257dc..f8fd7d5 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,12 +1,11 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' -ENV["RAILS_ENV"] ||= 'test' +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 File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' - -# DO NOT Add additional requires below this line. Rails is not loaded until this point! -# INSTEAD...put requires in dedicated files in spec/support so that folks browsing this -# can see all the config for a testing gem in one easy-to-find, well-named file. +# Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -21,7 +20,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. @@ -31,7 +30,9 @@ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" - # See database_cleaner.rb about config.use_transactional_fixtures + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. # config.use_transactional_fixtures = true # RSpec Rails can automatically mix in different behaviours to your tests diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7ee86cc..ad7095f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,16 @@ # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause this -# file to always be loaded, without a need to explicitly require it in any files. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. # # Given that it is always loaded, you are encouraged to keep this file as # light-weight as possible. Requiring heavyweight dependencies from this file # will add to the boot time of your test suite on EVERY test run, even for an # individual file that may not need all of that loaded. Instead, consider making # a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need it. +# the additional setup, and require it from the spec files that actually need +# it. # # The `.rspec` file also contains a few flags that are not defaults but that # users commonly want. @@ -22,10 +24,10 @@ # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" # ...rather than: - # # => "be bigger than 2" + # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end @@ -38,21 +40,9 @@ mocks.verify_partial_doubles = true end - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed - # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. -=begin + # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with # `:focus` metadata. When nothing is tagged with `:focus`, all examples @@ -60,10 +50,15 @@ config.filter_run :focus config.run_all_when_everything_filtered = true - # Limits the available syntax to the non-monkey patched syntax that is recommended. - # For more details, see: + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching config.disable_monkey_patching! @@ -80,7 +75,18 @@ # 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.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed -=end end