Почему rspe c не запускает single spe c? - PullRequest
1 голос
/ 10 февраля 2020

Когда я пытаюсь запустить одиночный тест, например

bundle exec rspec spec/some_path/some_spec.rb

В любом случае он запускает все спецификации, как если бы я запускал bundle exec rspec spec/

Даже когда он распечатывает ошибочные спецификации, а я только копирую неудачные примеры и помещаю их снова, Rspe c запустит все существующие спецификации. Я не нашел никакой информации о таком поведении в документации rspe c. Большое спасибо, если знаете, что не так с моим кодом! (или конфигурация, я полагаю)

spec_helper.rb :

RSpec.configure do |config|
  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.shared_context_metadata_behavior = :apply_to_host_groups
  config.filter_run_when_matching :focus
  config.disable_monkey_patching!

  if config.files_to_run.one?
    config.default_formatter = 'doc'
  end

  config.profile_examples = 10
  config.order = :random
  Kernel.srand config.seed
end

require 'webmock/rspec'

def body_as_json
  json_str_to_hash response.body
end

def json_str_to_hash(str)
  JSON.parse(str).with_indifferent_access
end

.rspe c:

--require rails_helper
--format progress
--color
--order random
--profile 10

rails_helper.rb

# frozen_string_literal: true

unless ENV['COVERAGE'].to_s == ''
  require 'simplecov'
  SimpleCov.start 'rails'
end

ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
require 'capybara-screenshot/rspec'
require 'timecop'
require 'sidekiq/testing'
require 'database_cleaner'
require 'webmock/rspec'
require 'audited-rspec'

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

ActiveRecord::Base.connection.reconnect!

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  config.infer_base_class_for_anonymous_controllers = false

  config.include Capybara::DSL
  config.include FactoryBot::Syntax::Methods
  config.include CapybaraHelpers
  config.include ProcessingHelpers
  config.include RequestsHelper, type: :request
  config.include ApiHelper

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with :truncation, except: %w[spatial_ref_sys schema_migrations]
    Faker::Config.locale = :en
    # Rails.application.load_seed
    Sidekiq::Testing.fake!
  end

  config.around do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end

  # 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

  # RSpec Rails can automatically mix in different behaviours to your tests
  # based on their file location, for example enabling you to call `get` and
  # `post` in specs under `spec/controllers`.
  #
  # You can disable this behaviour by removing the line below, and instead
  # explicitly tag your specs with their type, e.g.:
  #
  #     RSpec.describe UsersController, :type => :controller do
  #       # ...
  #     end
  #
  # The different available types are documented in the features, such as in
  # https://relishapp.com/rspec/rspec-rails/docs
  config.infer_spec_type_from_file_location!

  # Filter lines from Rails gems in backtraces.
  config.filter_rails_from_backtrace!
  # arbitrary gems may also be filtered via:
  # config.filter_gems_from_backtrace("gem name")
end

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(
    app,
    phantomjs_logger: Rails.root.join('log', 'poltergeist.log'),
    inspector:        true
  )
end

Capybara.javascript_driver = :poltergeist
Capybara.server_port = 3001
Capybara.app_host = 'http://localhost:3001'
...