diff --git a/.gitignore b/.gitignore index 564f5168..fba20e1f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,9 @@ vendor/bundle *.DS_Store spec/dummy/log/* spec/dummy/db/*.sqlite3 +.ruby-version* +.ruby-gemset* +.rake_tasks +rspec_errors.txt +rspec_results.html +bin/ diff --git a/lib/generators/rspec/templates/decorator_spec.rb b/lib/generators/rspec/templates/decorator_spec.rb index b12fb8fa..6c6cf086 100644 --- a/lib/generators/rspec/templates/decorator_spec.rb +++ b/lib/generators/rspec/templates/decorator_spec.rb @@ -1,4 +1,9 @@ -require 'rails_helper' +<% require 'rspec/version' %> +<% if RSpec::Version::STRING.match(/\A3\.[^10]/) %> + require 'rails_helper' +<% else %> + require 'spec_helper' +<% end %> -RSpec.describe <%= class_name %>Decorator do +RSpec.describe <%= class_name %>Decorator, type: :decorator do end diff --git a/spec/draper/collection_decorator_spec.rb b/spec/draper/collection_decorator_spec.rb index d329e861..1e36901a 100644 --- a/spec/draper/collection_decorator_spec.rb +++ b/spec/draper/collection_decorator_spec.rb @@ -2,7 +2,7 @@ require 'support/shared_examples/view_helpers' module Draper - describe CollectionDecorator do + RSpec.describe CollectionDecorator do it_behaves_like "view helpers", CollectionDecorator.new([]) describe "#initialize" do @@ -141,7 +141,7 @@ module Draper it "delegates array methods to the decorated collection" do decorator = CollectionDecorator.new([]) - allow(decorator).to receive_message_chain(:decorated_collection, :[]).with(42).and_return(:delegated) + allow(decorator.decorated_collection).to receive(:[]).with(42).and_return(:delegated) expect(decorator[42]).to be :delegated end diff --git a/spec/draper/decoratable/equality_spec.rb b/spec/draper/decoratable/equality_spec.rb index c2d96627..e244c1c2 100644 --- a/spec/draper/decoratable/equality_spec.rb +++ b/spec/draper/decoratable/equality_spec.rb @@ -2,7 +2,7 @@ require 'support/shared_examples/decoratable_equality' module Draper - describe Decoratable::Equality do + RSpec.describe Decoratable::Equality do describe "#==" do it_behaves_like "decoration-aware #==", Object.new.extend(Decoratable::Equality) end diff --git a/spec/draper/decoratable_spec.rb b/spec/draper/decoratable_spec.rb index 8e673fa6..04362853 100644 --- a/spec/draper/decoratable_spec.rb +++ b/spec/draper/decoratable_spec.rb @@ -2,7 +2,8 @@ require 'support/shared_examples/decoratable_equality' module Draper - describe Decoratable do + RSpec.describe Decoratable do + describe "#decorate" do it "returns a decorator for self" do product = Product.new diff --git a/spec/draper/decorated_association_spec.rb b/spec/draper/decorated_association_spec.rb index d68205bb..efe6c912 100644 --- a/spec/draper/decorated_association_spec.rb +++ b/spec/draper/decorated_association_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Draper - describe DecoratedAssociation do + Rspec.describe DecoratedAssociation do describe "#initialize" do it "accepts valid options" do valid_options = {with: Decorator, scope: :foo, context: {}} diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index 0f50aa4e..d1eccf07 100644 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -2,7 +2,7 @@ require 'support/shared_examples/view_helpers' module Draper - describe Decorator do + RSpec.describe Decorator do it_behaves_like "view helpers", Decorator.new(Model.new) describe "#initialize" do diff --git a/spec/draper/factory_spec.rb b/spec/draper/factory_spec.rb index 9a9ce24a..0085aa7c 100644 --- a/spec/draper/factory_spec.rb +++ b/spec/draper/factory_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Draper - describe Factory do + Rspec.describe Factory do describe "#initialize" do it "accepts valid options" do valid_options = {with: Decorator, context: {foo: "bar"}} @@ -89,7 +89,7 @@ module Draper end end - describe Factory::Worker do + Rspec.describe Factory::Worker do describe "#call" do it "calls the decorator method" do object = double diff --git a/spec/draper/finders_spec.rb b/spec/draper/finders_spec.rb index 131903e4..8266c9fe 100644 --- a/spec/draper/finders_spec.rb +++ b/spec/draper/finders_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Draper - describe Finders do + RSpec.describe Finders do protect_class ProductDecorator before { ProductDecorator.decorates_finders } diff --git a/spec/draper/helper_proxy_spec.rb b/spec/draper/helper_proxy_spec.rb index de4d030d..3a9ded00 100644 --- a/spec/draper/helper_proxy_spec.rb +++ b/spec/draper/helper_proxy_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Draper - describe HelperProxy do + RSpec.describe HelperProxy do describe "#initialize" do it "sets the view context" do view_context = double diff --git a/spec/draper/lazy_helpers_spec.rb b/spec/draper/lazy_helpers_spec.rb index e53c618e..f2354df3 100644 --- a/spec/draper/lazy_helpers_spec.rb +++ b/spec/draper/lazy_helpers_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Draper - describe LazyHelpers do + RSpec.describe LazyHelpers do describe "#method_missing" do let(:decorator) do Struct.new(:helpers){include Draper::LazyHelpers}.new(double) diff --git a/spec/draper/undecorate_spec.rb b/spec/draper/undecorate_spec.rb index c0aff84f..e22da3e3 100644 --- a/spec/draper/undecorate_spec.rb +++ b/spec/draper/undecorate_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Draper, '.undecorate' do +RSpec.describe Draper, '.undecorate' do it 'undecorates a decorated object' do object = Model.new decorator = Draper::Decorator.new(object) diff --git a/spec/draper/view_context/build_strategy_spec.rb b/spec/draper/view_context/build_strategy_spec.rb index 54774926..10743abd 100644 --- a/spec/draper/view_context/build_strategy_spec.rb +++ b/spec/draper/view_context/build_strategy_spec.rb @@ -9,7 +9,7 @@ def fake_controller(view_context = fake_view_context) end module Draper - describe ViewContext::BuildStrategy::Full do + RSpec.describe ViewContext::BuildStrategy::Full do describe "#call" do context "when a current controller is set" do it "returns the controller's view context" do @@ -86,7 +86,7 @@ def a_helper_method; end end end - describe ViewContext::BuildStrategy::Fast do + RSpec.describe ViewContext::BuildStrategy::Fast do describe "#call" do it "returns an instance of a subclass of ActionView::Base" do strategy = ViewContext::BuildStrategy::Fast.new diff --git a/spec/draper/view_context_spec.rb b/spec/draper/view_context_spec.rb index e62008cb..b191d0e7 100644 --- a/spec/draper/view_context_spec.rb +++ b/spec/draper/view_context_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Draper - describe ViewContext do + RSpec.describe ViewContext do describe "#view_context" do let(:base) { Class.new { def view_context; :controller_view_context; end } } let(:controller) { Class.new(base) { include ViewContext } } diff --git a/spec/draper/view_helpers_spec.rb b/spec/draper/view_helpers_spec.rb index cfa41e9a..8054508f 100644 --- a/spec/draper/view_helpers_spec.rb +++ b/spec/draper/view_helpers_spec.rb @@ -2,7 +2,7 @@ require 'support/shared_examples/view_helpers' module Draper - describe ViewHelpers do + RSpec.describe ViewHelpers do it_behaves_like "view helpers", Class.new{include ViewHelpers}.new end end diff --git a/spec/dummy/fast_spec/post_decorator_spec.rb b/spec/dummy/fast_spec/post_decorator_spec.rb index 1322fa42..9ea89942 100644 --- a/spec/dummy/fast_spec/post_decorator_spec.rb +++ b/spec/dummy/fast_spec/post_decorator_spec.rb @@ -7,7 +7,7 @@ Post = Struct.new(:id) { extend ActiveModel::Naming } -describe PostDecorator do +RSpec.describe PostDecorator do let(:decorator) { PostDecorator.new(object) } let(:object) { Post.new(42) } @@ -32,6 +32,6 @@ end it "can't be passed implicitly to url_for" do - expect{decorator.link}.to raise_error ArgumentError + expect{decorator.link}.to raise_error ArgumentError, /url_for/ end end diff --git a/spec/dummy/spec/decorators/active_model_serializers_spec.rb b/spec/dummy/spec/decorators/active_model_serializers_spec.rb index ee83e24d..c667f050 100644 --- a/spec/dummy/spec/decorators/active_model_serializers_spec.rb +++ b/spec/dummy/spec/decorators/active_model_serializers_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require_relative '../rails_helper' -describe Draper::CollectionDecorator do +RSpec.describe Draper::CollectionDecorator do describe "#active_model_serializer" do it "returns ActiveModel::Serializer::CollectionSerializer" do collection_decorator = Draper::CollectionDecorator.new([]) diff --git a/spec/dummy/spec/decorators/devise_spec.rb b/spec/dummy/spec/decorators/devise_spec.rb index ee7067b5..d2399c1b 100644 --- a/spec/dummy/spec/decorators/devise_spec.rb +++ b/spec/dummy/spec/decorators/devise_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require_relative '../rails_helper' if defined?(Devise) - describe "A decorator spec" do + RSpec.describe "A decorator spec" do it "can sign in a real user" do user = User.new sign_in user diff --git a/spec/dummy/spec/decorators/helpers_spec.rb b/spec/dummy/spec/decorators/helpers_spec.rb index eb171f89..8d32a545 100644 --- a/spec/dummy/spec/decorators/helpers_spec.rb +++ b/spec/dummy/spec/decorators/helpers_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require_relative '../rails_helper' -describe "A decorator spec" do +RSpec.describe "A decorator spec" do it "can access helpers through `helper`" do expect(helper.content_tag(:p, "Help!")).to eq "
Help!
" end diff --git a/spec/dummy/spec/decorators/post_decorator_spec.rb b/spec/dummy/spec/decorators/post_decorator_spec.rb index e1655b9a..97115f53 100644 --- a/spec/dummy/spec/decorators/post_decorator_spec.rb +++ b/spec/dummy/spec/decorators/post_decorator_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require_relative '../rails_helper' -describe PostDecorator do +RSpec.describe PostDecorator do let(:decorator) { PostDecorator.new(object) } let(:object) { Post.create } diff --git a/spec/dummy/spec/decorators/spec_type_spec.rb b/spec/dummy/spec/decorators/spec_type_spec.rb index 2c52c03a..d0ac746f 100644 --- a/spec/dummy/spec/decorators/spec_type_spec.rb +++ b/spec/dummy/spec/decorators/spec_type_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require_relative '../rails_helper' -describe "A spec in this folder" do +RSpec.describe "A spec in this folder" do it "is a decorator spec" do expect(RSpec.current_example.metadata[:type]).to be :decorator end diff --git a/spec/dummy/spec/decorators/view_context_spec.rb b/spec/dummy/spec/decorators/view_context_spec.rb index 2ba93a95..13498cf6 100644 --- a/spec/dummy/spec/decorators/view_context_spec.rb +++ b/spec/dummy/spec/decorators/view_context_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require_relative '../rails_helper' def it_does_not_leak_view_context 2.times do @@ -9,14 +9,14 @@ def it_does_not_leak_view_context end end -describe "A decorator spec", type: :decorator do +RSpec.describe "A decorator spec", type: :decorator do it_does_not_leak_view_context end -describe "A controller spec", type: :controller do +RSpec.describe "A controller spec", type: :controller do it_does_not_leak_view_context end -describe "A mailer spec", type: :mailer do +RSpec.describe "A mailer spec", type: :mailer do it_does_not_leak_view_context end diff --git a/spec/dummy/spec/mailers/post_mailer_spec.rb b/spec/dummy/spec/mailers/post_mailer_spec.rb index 4ab0135d..b6a4d810 100644 --- a/spec/dummy/spec/mailers/post_mailer_spec.rb +++ b/spec/dummy/spec/mailers/post_mailer_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require_relative '../rails_helper' -describe PostMailer do +RSpec.describe PostMailer do describe "#decorated_email" do let(:email_body) { Capybara.string(email.body.to_s) } let(:email) { PostMailer.decorated_email(post).deliver } diff --git a/spec/dummy/spec/models/mongoid_post_spec.rb b/spec/dummy/spec/models/mongoid_post_spec.rb index 1707bd1a..ea139585 100644 --- a/spec/dummy/spec/models/mongoid_post_spec.rb +++ b/spec/dummy/spec/models/mongoid_post_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' -require 'shared_examples/decoratable' +require_relative '../spec_helper' +require_relative '../shared_examples/decoratable' if defined?(Mongoid) - describe MongoidPost do + RSpec.describe MongoidPost do it_behaves_like "a decoratable model" end end diff --git a/spec/dummy/spec/models/post_spec.rb b/spec/dummy/spec/models/post_spec.rb index 22a5fb61..7dc62136 100644 --- a/spec/dummy/spec/models/post_spec.rb +++ b/spec/dummy/spec/models/post_spec.rb @@ -1,5 +1,5 @@ -require 'spec_helper' -require 'shared_examples/decoratable' +require_relative '../spec_helper' +require_relative '../shared_examples/decoratable' RSpec.describe Post do it_behaves_like 'a decoratable model' diff --git a/spec/dummy/spec/rails_helper.rb b/spec/dummy/spec/rails_helper.rb new file mode 100644 index 00000000..e6a4ed10 --- /dev/null +++ b/spec/dummy/spec/rails_helper.rb @@ -0,0 +1,34 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort('Rails 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! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# 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 } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +unless ENV['RAILS_VERSION'] == '4.0' + ActiveRecord::Migration.maintain_test_schema! +end + +RSpec.configure do |config| + config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.use_transactional_fixtures = true + config.infer_spec_type_from_file_location! +end diff --git a/spec/dummy/spec/shared_examples/decoratable.rb b/spec/dummy/spec/shared_examples/decoratable.rb index 72d46d16..a23428fb 100644 --- a/spec/dummy/spec/shared_examples/decoratable.rb +++ b/spec/dummy/spec/shared_examples/decoratable.rb @@ -1,4 +1,4 @@ -shared_examples_for "a decoratable model" do +RSpec.shared_examples_for "a decoratable model" do describe ".decorate" do it "applies a collection decorator to a scope" do described_class.create diff --git a/spec/dummy/spec/spec_helper.rb b/spec/dummy/spec/spec_helper.rb index aa3282b2..32edd580 100644 --- a/spec/dummy/spec/spec_helper.rb +++ b/spec/dummy/spec/spec_helper.rb @@ -1,8 +1,60 @@ -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rspec/rails' - RSpec.configure do |config| - config.expect_with(:rspec) {|c| c.syntax = :expect} + 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.disable_monkey_patching! + +# 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 + + # 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://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 + + # 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 + + # 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 + + # 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 diff --git a/spec/integration/integration_spec.rb b/spec/integration/integration_spec.rb index f3bd556d..81a49aba 100644 --- a/spec/integration/integration_spec.rb +++ b/spec/integration/integration_spec.rb @@ -13,7 +13,7 @@ spec_types.each do |type, (path, controller)| page = app.get(path) - describe "in a #{type}" do + RSpec.describe "in a #{type}" do it "runs in the correct environment" do expect(page).to have_text(app.environment).in("#environment") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af025e0e..f2d7011d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,11 +11,26 @@ require 'action_controller/test_case' RSpec.configure do |config| - config.expect_with(:rspec) {|c| c.syntax = :expect} - config.order = :random + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + config.mock_with :rspec do |mocks| mocks.yield_receiver_to_any_instance_implementation_blocks = true end + + config.filter_run :focus + config.run_all_when_everything_filtered = true + config.disable_monkey_patching! + + if config.files_to_run.one? + config.default_formatter = 'doc' + else + config.default_formatter = 'progress' + end + + config.order = :random + Kernel.srand config.seed end class Model; include Draper::Decoratable; end diff --git a/spec/support/dummy_app.rb b/spec/support/dummy_app.rb index c205f86f..5ab6a90a 100644 --- a/spec/support/dummy_app.rb +++ b/spec/support/dummy_app.rb @@ -7,7 +7,7 @@ class DummyApp def initialize(environment) - raise ArgumentError, "Environment must be development or production" unless ["development", "production"].include?(environment.to_s) + raise ArgumentError, 'Environment must be development or production' unless ['development', 'production', 'test'].include?(environment.to_s) @environment = environment end diff --git a/spec/support/matchers/have_text.rb b/spec/support/matchers/have_text.rb index b5010af7..fdc98e6b 100644 --- a/spec/support/matchers/have_text.rb +++ b/spec/support/matchers/have_text.rb @@ -1,3 +1,4 @@ +require 'spec_helper' require 'capybara' module HaveTextMatcher diff --git a/spec/support/shared_examples/decoratable_equality.rb b/spec/support/shared_examples/decoratable_equality.rb index 6a7f3adf..d97f7c3c 100644 --- a/spec/support/shared_examples/decoratable_equality.rb +++ b/spec/support/shared_examples/decoratable_equality.rb @@ -1,4 +1,6 @@ -shared_examples_for "decoration-aware #==" do |subject| +require 'spec_helper' + +RSpec.shared_examples_for "decoration-aware #==" do |subject| it "is true for itself" do expect(subject == subject).to be_truthy end diff --git a/spec/support/shared_examples/view_helpers.rb b/spec/support/shared_examples/view_helpers.rb index df8e5bef..22863bd5 100644 --- a/spec/support/shared_examples/view_helpers.rb +++ b/spec/support/shared_examples/view_helpers.rb @@ -1,4 +1,6 @@ -shared_examples_for "view helpers" do |subject| +require 'spec_helper' + +RSpec.shared_examples_for "view helpers" do |subject| describe "#helpers" do it "returns the current view context" do allow(Draper::ViewContext).to receive_messages current: :current_view_context @@ -12,6 +14,13 @@ end describe "#localize" do + let(:helpers) { double } + + before :each do + allow(subject).to receive(:helpers) { helpers } + allow(helpers).to receive(:localize) + end + it "delegates to #helpers" do allow(subject).to receive(:helpers).and_return(double) expect(subject.helpers).to receive(:localize).with(:an_object, some: "parameter")