Skip to content

Commit

Permalink
fix for update rspec to 3.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
takuyan committed Feb 8, 2015
1 parent 81471af commit 6992aed
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 95 deletions.
6 changes: 5 additions & 1 deletion spec/controllers/accounts_controller_spec.rb
@@ -1,4 +1,4 @@
require "spec_helper"
require 'rails_helper'

describe AccountsController do
let(:user) { create(:user) }
Expand All @@ -13,4 +13,8 @@
expect(response).to be_success
end
end

describe 'hoge' do
it { expect(user).to be_valid }
end
end
2 changes: 1 addition & 1 deletion spec/controllers/statuses_controller_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe StatusesController do
let(:user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/tasks_controller_spec.rb
@@ -1,4 +1,4 @@
require "spec_helper"
require 'rails_helper'

describe TasksController do
let(:user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/weeks_controller_spec.rb
@@ -1,4 +1,4 @@
require "spec_helper"
require 'rails_helper'

describe WeeksController do
let(:user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/features/sign_in_spec.rb
@@ -1,4 +1,4 @@
require "spec_helper"
require 'rails_helper'

describe 'sign_in' do
let(:new_user) { build(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/features/tasks_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

feature 'Tasks List Spec' do
let(:user) { create :user }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/task_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Task do
let(:task) { create(:task) }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Expand Up @@ -47,7 +47,7 @@
context 'userがいない' do
let(:new_user) { create(:user) }
before do
User.stub_chain(:where, :first_or_initialize).and_return(new_user)
allow(User).to receive_message_chain(:where, :first_or_initialize).and_return(new_user)
end
it { expect(subject).to eq new_user }
it { expect(subject).to be_instance_of User }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/week_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Week do
let(:week) { create(:week) }
Expand Down
96 changes: 96 additions & 0 deletions spec/rails_helper.rb
@@ -0,0 +1,96 @@
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'json_expressions/rspec'

# Load all railties files
Rails.application.railties.to_a { |r| r.eager_load! }

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
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.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

RSpec.configure do |config|
config.raise_errors_for_deprecations!
config.infer_spec_type_from_file_location!

# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr

# 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 = false

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false

# 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"

# For capybara
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.register_driver :rack_test do |app|
Capybara::RackTest::Driver.new(app, headers: {'HTTP_ACCEPT_LANGUAGE' => 'ja-JP'})
end
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, timeout: 360, headers: {'HTTP_ACCEPT_LANGUAGE' => 'ja-JP'})
end
Capybara.javascript_driver = :poltergeist

# For database cleaner
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end

config.before(:each) do |example|
if example.metadata[:js]
page.driver.resize(1024, 2048)
end
I18n.locale = (ENV['CI'] == 'ON') ? :en : :ja
DatabaseCleaner.strategy = :truncation
end

config.after(:each) do |example|
DatabaseCleaner.clean
if example.metadata[:js]
load "#{Rails.root}/db/seeds.rb"
end
end

# macro
config.include FeatureMacros, type: :feature
config.include FactoryGirl::Syntax::Methods
config.include Delorean

# metadata setting
#config.treat_symbols_as_metadata_keys_with_true_values = true

config.before(:all) do
FactoryGirl.reload
end

# faker
Faker::Config.locale = :en

# master data
#load "#{Rails.root}/db/seeds.rb"
end
163 changes: 77 additions & 86 deletions spec/spec_helper.rb
@@ -1,96 +1,87 @@
require 'rubygems'

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'json_expressions/rspec'

# Load all railties files
Rails.application.railties.to_a { |r| r.eager_load! }

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
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.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

# 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.
#
# 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 `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# 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"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end

# 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 = false
# 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
# get run.
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:
# - 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://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# 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
# 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"

# For capybara
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.register_driver :rack_test do |app|
Capybara::RackTest::Driver.new(app, headers: {'HTTP_ACCEPT_LANGUAGE' => 'ja-JP'})
end
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, timeout: 360, headers: {'HTTP_ACCEPT_LANGUAGE' => 'ja-JP'})
end
Capybara.javascript_driver = :poltergeist

# For database cleaner
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
if example.metadata[:js]
page.driver.resize(1024, 2048)
end
I18n.locale = (ENV['CI'] == 'ON') ? :en : :ja
DatabaseCleaner.strategy = :truncation
end

config.after(:each) do
DatabaseCleaner.clean
if example.metadata[:js]
load "#{Rails.root}/db/seeds.rb"
end
end

# macro
config.include FeatureMacros, type: :feature
config.include FactoryGirl::Syntax::Methods
config.include Delorean

# metadata setting
config.treat_symbols_as_metadata_keys_with_true_values = true

config.before(:all) do
FactoryGirl.reload
end

# faker
Faker::Config.locale = :en

# master data
load "#{Rails.root}/db/seeds.rb"
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

0 comments on commit 6992aed

Please sign in to comment.