diff --git a/Gemfile b/Gemfile index 77aa87771c..86da1d6ddd 100644 --- a/Gemfile +++ b/Gemfile @@ -19,3 +19,6 @@ gem 'spring-commands-teaspoon', group: :development gem 'pageflow-theme-doc-publisher', git: 'https://github.com/tf/pageflow-theme-doc-publisher' gem 'coveralls', require: false + +# Early failure output +gem 'rspec-instafail', '~> 0.4.0', require: false diff --git a/pageflow.gemspec b/pageflow.gemspec index 4f9bb33a70..0302517344 100644 --- a/pageflow.gemspec +++ b/pageflow.gemspec @@ -127,7 +127,10 @@ Gem::Specification.new do |s| s.add_development_dependency 'mysql2', '~> 0.3.16' # Testing framework - s.add_development_dependency 'rspec-rails', '~> 2.14' + s.add_development_dependency 'rspec-rails', '~> 3.4' + + # Matchers like "to have(3).items" + s.add_development_dependency 'rspec-collection_matchers', '~> 1.1' # Browser like integration testing s.add_development_dependency 'capybara', '~> 2.4' @@ -147,9 +150,6 @@ Gem::Specification.new do |s| # Freeze time in tests s.add_development_dependency 'timecop', '~> 0.7.1' - # Early failure output - s.add_development_dependency 'rspec-instafail', '~> 0.2.6' - # Colorized console output s.add_development_dependency 'colorize', '~> 0.7.5' diff --git a/spec/models/pageflow/ability_spec.rb b/spec/models/pageflow/ability_spec.rb index 91d95a1b85..bf0ecc0667 100644 --- a/spec/models/pageflow/ability_spec.rb +++ b/spec/models/pageflow/ability_spec.rb @@ -62,7 +62,7 @@ module Pageflow user = build(:user, :account_manager) ability = Ability.new(user) - expect(ability.can?(:create, User)).to be_true + expect(ability.can?(:create, User)).to be true end it 'can read folders of own account' do diff --git a/spec/pageflow/seeds_spec.rb b/spec/pageflow/seeds_spec.rb index a017714eda..b5c7f5d802 100644 --- a/spec/pageflow/seeds_spec.rb +++ b/spec/pageflow/seeds_spec.rb @@ -65,7 +65,7 @@ module SeedsDsl SeedsDsl.default_user_password('!Other123') user = SeedsDsl.user(email: 'editor@example.com', account: create(:account)) - expect(user.valid_password?('!Other123')).to be_true + expect(user.valid_password?('!Other123')).to be true end it 'allows overriding attributes in block' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0bfb6fdc84..0ec54b9574 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ Coveralls.wear! require 'rspec/rails' +require 'rspec/collection_matchers' require 'domino' Dir[File.join(File.dirname(__FILE__), 'support/{config,dominos,helpers,matchers}/**/*.rb')].each { |file| require(file) } @@ -15,5 +16,9 @@ config.use_transactional_fixtures = false config.infer_base_class_for_anonymous_controllers = false + config.infer_spec_type_from_file_location! + + config.example_status_persistence_file_path = './tmp/rspec_failures' + config.order = "random" end diff --git a/spec/state_machines/pageflow/image_file_state_machine_spec.rb b/spec/state_machines/pageflow/image_file_state_machine_spec.rb index a96e7b4383..96fc0134bd 100644 --- a/spec/state_machines/pageflow/image_file_state_machine_spec.rb +++ b/spec/state_machines/pageflow/image_file_state_machine_spec.rb @@ -9,7 +9,7 @@ module Pageflow file.process - expect(file.reload.attachment.exists?(:thumbnail)).to be_true + expect(file.reload.attachment.exists?(:thumbnail)).to be true end it 'sets state to processed' do @@ -35,7 +35,7 @@ module Pageflow file.process - expect(file.reload.attachment.exists?(:thumbnail)).to be_true + expect(file.reload.attachment.exists?(:thumbnail)).to be true end it 'sets state to processed' do diff --git a/spec/support/helpers/view_component_example_group.rb b/spec/support/helpers/view_component_example_group.rb index 5604d3ed96..a88be9a8e9 100644 --- a/spec/support/helpers/view_component_example_group.rb +++ b/spec/support/helpers/view_component_example_group.rb @@ -27,8 +27,5 @@ def render(*args, &block) end RSpec.configure do |config| - config.include(ViewComponentExampleGroup, - :example_group => lambda { |example_group, metadata| - %r(spec/views/components) =~ example_group[:file_path] - }) + config.include(ViewComponentExampleGroup, type: :view_component) end diff --git a/spec/support/helpers/zencoder_api_double.rb b/spec/support/helpers/zencoder_api_double.rb index 590773f4eb..5d84f96e1d 100644 --- a/spec/support/helpers/zencoder_api_double.rb +++ b/spec/support/helpers/zencoder_api_double.rb @@ -4,7 +4,7 @@ module ZencoderApiDouble def creating_job_with_id(id) api = double - api.stub(:create_job).and_return(id) + allow(api).to receive(:create_job).and_return(id) api end @@ -12,9 +12,9 @@ def creating_job_with_id(id) def finished api = double - api.stub(:create_job).and_return(1) - api.stub(:get_info).and_return(finished_info_result) - api.stub(:get_input_details).and_return(input_details) + allow(api).to receive(:create_job).and_return(1) + allow(api).to receive(:get_info).and_return(finished_info_result) + allow(api).to receive(:get_input_details).and_return(input_details) api end @@ -22,9 +22,9 @@ def finished def finished_but_failed api = double - api.stub(:create_job).and_return(1) - api.stub(:get_info).and_return(failed_info_result) - api.stub(:get_input_details).and_return(input_details) + allow(api).to receive(:create_job).and_return(1) + allow(api).to receive(:get_info).and_return(failed_info_result) + allow(api).to receive(:get_input_details).and_return(input_details) api end @@ -32,9 +32,9 @@ def finished_but_failed def once_pending_then_finished api = double - api.stub(:create_job).and_return(1) - api.stub(:get_info).and_return(pending_info_result, finished_info_result) - api.stub(:get_input_details).and_return(input_details) + allow(api).to receive(:create_job).and_return(1) + allow(api).to receive(:get_info).and_return(pending_info_result, finished_info_result) + allow(api).to receive(:get_input_details).and_return(input_details) api end @@ -42,9 +42,9 @@ def once_pending_then_finished def pending(options = {}) api = double - api.stub(:create_job).and_return(1) - api.stub(:get_info).and_return(pending_info_result(options)) - api.stub(:get_input_details).and_return(input_details) + allow(api).to receive(:create_job).and_return(1) + allow(api).to receive(:get_info).and_return(pending_info_result(options)) + allow(api).to receive(:get_input_details).and_return(input_details) api end @@ -52,7 +52,7 @@ def pending(options = {}) def recoverably_failing api = double - api.stub(:get_info).and_raise(Pageflow::ZencoderApi::RecoverableError) + allow(api).to receive(:get_info).and_raise(Pageflow::ZencoderApi::RecoverableError) api end @@ -60,7 +60,7 @@ def recoverably_failing def unrecoverably_failing api = double - api.stub(:get_info).and_raise(Pageflow::ZencoderApi::UnrecoverableError) + allow(api).to receive(:get_info).and_raise(Pageflow::ZencoderApi::UnrecoverableError) api end @@ -68,7 +68,7 @@ def unrecoverably_failing private def double - RSpec::Mocks::Mock.new('zencoder api') + RSpec::Mocks::Double.new('zencoder api') end def pending_info_result(options = {}) @@ -95,3 +95,5 @@ def input_details :duration_in_ms => 5000 } end end + +RSpec::Mocks::Syntax.enable_expect(ZencoderApiDouble) diff --git a/spec/views/components/pageflow/admin/embedded_index_table_spec.rb b/spec/views/components/pageflow/admin/embedded_index_table_spec.rb index 4d3bd8aca1..3aff663838 100644 --- a/spec/views/components/pageflow/admin/embedded_index_table_spec.rb +++ b/spec/views/components/pageflow/admin/embedded_index_table_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' module Pageflow - describe Admin::EmbeddedIndexTable do + describe Admin::EmbeddedIndexTable, type: :view_component do before do helper.extend(ActiveAdmin::ViewHelpers) - helper.stub(:url_for) + allow(helper).to receive(:url_for) end it 'renders table of entries' do diff --git a/spec/views/components/pageflow/admin/grouped_folder_list_spec.rb b/spec/views/components/pageflow/admin/grouped_folder_list_spec.rb index 06530c3798..cf95760245 100644 --- a/spec/views/components/pageflow/admin/grouped_folder_list_spec.rb +++ b/spec/views/components/pageflow/admin/grouped_folder_list_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' module Pageflow - describe Admin::GroupedFolderList do + describe Admin::GroupedFolderList, type: :view_component do it 'renders all link' do render([], :active_id => 3) diff --git a/spec/views/components/pageflow/admin/tabs_view_spec.rb b/spec/views/components/pageflow/admin/tabs_view_spec.rb index c92860e147..2da243dd4c 100644 --- a/spec/views/components/pageflow/admin/tabs_view_spec.rb +++ b/spec/views/components/pageflow/admin/tabs_view_spec.rb @@ -2,7 +2,7 @@ module Pageflow module Admin - describe TabsView do + describe TabsView, type: :view_component do let(:tab_view_component) do Class.new(ViewComponent) do def self.name @@ -98,7 +98,7 @@ def build(custom) it 'does not render links for tabs we are not authorized for' do tabs = [{name: :some_tab, component: tab_view_component}] - helper.stub(:authorized?) { false } + allow(helper).to receive(:authorized?) { false } render(tabs, authorize: true) @@ -108,7 +108,7 @@ def build(custom) it 'renders links for tabs we are authorized for' do tabs = [{name: :some_tab, component: tab_view_component}] - helper.stub(:authorized?) { true } + allow(helper).to receive(:authorized?) { true } render(tabs, authorize: true) @@ -118,7 +118,7 @@ def build(custom) it 'passes :view action and component class to authorized? method' do tabs = [{name: :some_tab, component: tab_view_component}] - helper.stub(:authorized?) { true } + allow(helper).to receive(:authorized?) { true } render(tabs, authorize: true)