Skip to content

Commit

Permalink
add RSpec, test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwoldatwork committed Sep 13, 2018
1 parent 6f5638d commit 12bbf7f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 22 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'pry'
end

group :development do
Expand All @@ -45,7 +46,9 @@ end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'capybara'#, '>= 2.15'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'rspec-rails'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
Expand Down
17 changes: 15 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ GEM
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.6.0)
capybara (3.7.2)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -65,6 +65,7 @@ GEM
chromedriver-helper (1.2.0)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
coderay (1.1.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand All @@ -74,6 +75,7 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.4)
database_cleaner (1.7.0)
declarative (0.0.10)
declarative-option (0.1.0)
devise (4.5.0)
Expand All @@ -85,6 +87,11 @@ GEM
diff-lcs (1.3)
erubi (1.7.1)
execjs (2.7.0)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
faraday (0.15.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.25)
Expand Down Expand Up @@ -142,6 +149,9 @@ GEM
orm_adapter (0.5.0)
os (1.0.0)
pg (1.0.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.5)
Expand Down Expand Up @@ -255,14 +265,17 @@ PLATFORMS
DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
capybara (>= 2.15)
capybara
chromedriver-helper
coffee-rails (~> 4.2)
database_cleaner
devise
factory_bot_rails
google-api-client
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
pg (>= 0.18, < 2.0)
pry
puma (~> 3.11)
rails (~> 5.2.1)
rspec-rails
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/site_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'

class SiteControllerSpec < ActionDispatch::IntegrationTest
describe "should get index" do
get :index
expect(response).to be_successful
end
end
14 changes: 14 additions & 0 deletions spec/features/login_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rails_helper'

feature "Login Flow", js: true do

describe "homepage" do
before do
visit root_path
end

it "has content" do
expect(page).to have_content "Touchpoints"
end
end
end
54 changes: 50 additions & 4 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
Expand All @@ -30,14 +32,58 @@
puts e.to_s.strip
exit 1
end

# for Capybara
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :selenium
Capybara.default_max_wait_time = 30
Capybara.raise_server_errors = false

RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/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
# for factory_bot_rails
config.include FactoryBot::Syntax::Methods

# for Devise
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Warden::Test::Helpers

# for Database Cleaner
config.use_transactional_fixtures = false

config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
DatabaseCleaner.strategy = :transaction
end

config.before(:each, type: :feature) do
config.include Capybara::DSL
# :rack_test driver's Rack app under test shares database connection
# with the specs, so continue to use transaction strategy for speed.
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test

if !driver_shares_db_connection_with_specs
# Driver is probably for an external browser with an app
# under test that does *not* share a database connection with the
# specs, so use truncation strategy.
DatabaseCleaner.strategy = :truncation
end
end

config.before(:each) do
DatabaseCleaner.start
end

config.append_after(:each) do
DatabaseCleaner.clean
end

# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
Expand Down
13 changes: 12 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# it.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'devise'
require 'pry'

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
Expand All @@ -26,6 +29,7 @@
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
expectations.syntax = :expect
end

# rspec-mocks config goes here. You can use an alternate test double
Expand All @@ -46,14 +50,14 @@

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# This allows 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 get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus

=begin
# 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.
Expand Down Expand Up @@ -93,4 +97,11 @@
# as the one that triggered the failure.
Kernel.srand config.seed
=end

# For Devise
Warden.test_mode!

config.after do
Warden.test_reset!
end
end
5 changes: 0 additions & 5 deletions test/application_system_test_case.rb

This file was deleted.

9 changes: 0 additions & 9 deletions test/controllers/site_controller_test.rb

This file was deleted.

0 comments on commit 12bbf7f

Please sign in to comment.