Use RSpec as receiver for rspec DSL methods

* I dislike the global infection RSpec does. This commit is a first step
  to get a rid of it.
* Also remove the need for `require 'spec_helper` in each spec file with
  adjusting `.rspec`.
This commit is contained in:
Markus Schirp 2014-08-10 21:04:05 +00:00
parent 978e246b67
commit 6df5811a87
46 changed files with 52 additions and 142 deletions

1
.rspec
View file

@ -1,4 +1,5 @@
--color --color
--require spec_helper
--format progress --format progress
--warnings --warnings
--order random --order random

View file

@ -1,9 +1,4 @@
# encoding: UTF-8 RSpec.describe 'Mutant on ruby corpus' do
require 'parallel'
require 'spec_helper'
describe 'Mutant on ruby corpus' do
before do before do
skip 'Corpus test is deactivated on 1.9.3' if RUBY_VERSION.eql?('1.9.3') skip 'Corpus test is deactivated on 1.9.3' if RUBY_VERSION.eql?('1.9.3')

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe 'null integration' do
describe 'null integration' do
let(:base_cmd) { 'bundle exec mutant -I lib --require test_app "TestApp*"' } let(:base_cmd) { 'bundle exec mutant -I lib --require test_app "TestApp*"' }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe 'rspec integration' do
describe 'rspec integration' do
let(:base_cmd) { 'bundle exec mutant -I lib --require test_app --use rspec' } let(:base_cmd) { 'bundle exec mutant -I lib --require test_app --use rspec' }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe do
describe do
specify 'mutant should not crash for any node parser can generate' do specify 'mutant should not crash for any node parser can generate' do
Mutant::AST::Types::ALL.each do |type| Mutant::AST::Types::ALL.each do |type|

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe 'as a zombie' do
describe 'as a zombie' do
specify 'it allows to create zombie from mutant' do specify 'it allows to create zombie from mutant' do
expect { Mutant.zombify }.to change { defined?(Zombie) }.from(nil).to('constant') expect { Mutant.zombify }.to change { defined?(Zombie) }.from(nil).to('constant')
expect(Zombie.constants).to include(:Mutant) expect(Zombie.constants).to include(:Mutant)

View file

@ -1,4 +1,4 @@
shared_examples_for 'a method matcher' do RSpec.shared_examples_for 'a method matcher' do
before { subject } before { subject }

View file

@ -1,6 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
shared_examples_for 'a mutator' do RSpec.shared_examples_for 'a mutator' do
subject { object.each(node, &yields.method(:<<)) } subject { object.each(node, &yields.method(:<<)) }
let(:yields) { [] } let(:yields) { [] }
@ -48,7 +48,7 @@ shared_examples_for 'a mutator' do
end end
end end
shared_examples_for 'a noop mutator' do RSpec.shared_examples_for 'a noop mutator' do
let(:mutations) { [] } let(:mutations) { [] }
it_should_behave_like 'a mutator' it_should_behave_like 'a mutator'

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.shared_examples_for 'an invalid cli run' do
shared_examples_for 'an invalid cli run' do
it 'raises error' do it 'raises error' do
expect do expect do
subject subject
@ -8,13 +6,13 @@ shared_examples_for 'an invalid cli run' do
end end
end end
shared_examples_for 'a cli parser' do RSpec.shared_examples_for 'a cli parser' do
it { expect(subject.config.integration).to eql(expected_integration) } it { expect(subject.config.integration).to eql(expected_integration) }
it { expect(subject.config.reporter).to eql(expected_reporter) } it { expect(subject.config.reporter).to eql(expected_reporter) }
it { expect(subject.config.matcher_config).to eql(expected_matcher_config) } it { expect(subject.config.matcher_config).to eql(expected_matcher_config) }
end end
describe Mutant::CLI do RSpec.describe Mutant::CLI do
let(:object) { described_class } let(:object) { described_class }
describe '.run' do describe '.run' do

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Context, '#root' do
describe Mutant::Context, '#root' do
subject { object.root } subject { object.root }
let(:object) { described_class.allocate } let(:object) { described_class.allocate }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Context::Scope, '#root' do
describe Mutant::Context::Scope, '#root' do
subject { object.root(node) } subject { object.root(node) }
let(:object) { described_class.new(TestApp::Literal, path) } let(:object) { described_class.new(TestApp::Literal, path) }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Context::Scope, '#unqualified_name' do
describe Mutant::Context::Scope, '#unqualified_name' do
subject { object.unqualified_name } subject { object.unqualified_name }
let(:path) { double('Path') } let(:path) { double('Path') }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Diff do
describe Mutant::Diff do
let(:object) { described_class } let(:object) { described_class }
describe '.build' do describe '.build' do

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Expression::Method do
describe Mutant::Expression::Method do
let(:object) { described_class.parse(input) } let(:object) { described_class.parse(input) }
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Expression::Methods do
describe Mutant::Expression::Methods do
let(:object) { described_class.parse(input) } let(:object) { described_class.parse(input) }
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Expression::Namespace::Exact do
describe Mutant::Expression::Namespace::Exact do
let(:object) { described_class.parse(input) } let(:object) { described_class.parse(input) }
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Expression::Namespace::Recursive do
describe Mutant::Expression::Namespace::Recursive do
let(:object) { described_class.parse(input) } let(:object) { described_class.parse(input) }
let(:input) { 'TestApp::Literal*' } let(:input) { 'TestApp::Literal*' }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Expression do
describe Mutant::Expression do
let(:object) { described_class } let(:object) { described_class }
describe '.try_parse' do describe '.try_parse' do

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Integration do
describe Mutant::Integration do
let(:class_under_test) do let(:class_under_test) do
Class.new(described_class) Class.new(described_class)
@ -14,7 +12,7 @@ describe Mutant::Integration do
end end
end end
describe Mutant::Integration::Null do RSpec.describe Mutant::Integration::Null do
let(:object) { described_class.new } let(:object) { described_class.new }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Isolation::None do
describe Mutant::Isolation::None do
before do before do
@initial = 1 @initial = 1
end end
@ -24,7 +22,7 @@ describe Mutant::Isolation::None do
end end
end end
describe Mutant::Isolation::Fork do RSpec.describe Mutant::Isolation::Fork do
before do before do
@initial = 1 @initial = 1
end end

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Loader::Eval, '.call' do
describe Mutant::Loader::Eval, '.call' do
subject { object.call(node, mutation_subject) } subject { object.call(node, mutation_subject) }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Chain do
describe Mutant::Matcher::Chain do
let(:object) { described_class.new(matchers) } let(:object) { described_class.new(matchers) }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Compiler::SubjectPrefix do
describe Mutant::Matcher::Compiler::SubjectPrefix do
let(:object) { described_class.new(Mutant::Expression.parse('Foo*')) } let(:object) { described_class.new(Mutant::Expression.parse('Foo*')) }
let(:_subject) { double('Subject', expression: Mutant::Expression.parse(subject_expression)) } let(:_subject) { double('Subject', expression: Mutant::Expression.parse(subject_expression)) }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Compiler do
describe Mutant::Matcher::Compiler do
let(:object) { described_class } let(:object) { described_class }
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Filter do
describe Mutant::Matcher::Filter do
let(:object) { described_class.new(matcher, predicate) } let(:object) { described_class.new(matcher, predicate) }
describe '#each' do describe '#each' do

View file

@ -1,7 +1,5 @@
require 'spec_helper'
# rubocop:disable ClassAndModuleChildren # rubocop:disable ClassAndModuleChildren
describe Mutant::Matcher::Method::Instance do RSpec.describe Mutant::Matcher::Method::Instance do
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }
let(:reporter) { Fixtures::TEST_CONFIG.reporter } let(:reporter) { Fixtures::TEST_CONFIG.reporter }

View file

@ -1,7 +1,5 @@
require 'spec_helper'
# rubocop:disable ClassAndModuleChildren # rubocop:disable ClassAndModuleChildren
describe Mutant::Matcher::Method::Singleton, '#each' do RSpec.describe Mutant::Matcher::Method::Singleton, '#each' do
subject { object.each { |subject| yields << subject } } subject { object.each { |subject| yields << subject } }
let(:object) { described_class.new(env, scope, method) } let(:object) { described_class.new(env, scope, method) }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Methods::Instance, '#each' do
describe Mutant::Matcher::Methods::Instance, '#each' do
let(:object) { described_class.new(env, Foo) } let(:object) { described_class.new(env, Foo) }
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Methods::Singleton, '#each' do
describe Mutant::Matcher::Methods::Singleton, '#each' do
let(:object) { described_class.new(env, Foo) } let(:object) { described_class.new(env, Foo) }
let(:env) { Fixtures::TEST_ENV } let(:env) { Fixtures::TEST_ENV }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Namespace do
describe Mutant::Matcher::Namespace do
let(:object) { described_class.new(env, Mutant::Expression.parse('TestApp*')) } let(:object) { described_class.new(env, Mutant::Expression.parse('TestApp*')) }
let(:yields) { [] } let(:yields) { [] }
let(:env) { double('Env') } let(:env) { double('Env') }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Matcher::Null do
describe Mutant::Matcher::Null do
let(:object) { described_class.new } let(:object) { described_class.new }
describe '#each' do describe '#each' do

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Mutation do
describe Mutant::Mutation do
class TestMutation < Mutant::Mutation class TestMutation < Mutant::Mutation
SYMBOL = 'test'.freeze SYMBOL = 'test'.freeze

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Mutator::Node do
describe Mutant::Mutator::Node do
Mutant::Meta::Example::ALL.each do |example| Mutant::Meta::Example::ALL.each do |example|
context "on #{example.node.type.inspect}" do context "on #{example.node.type.inspect}" do
it 'generates the correct mutations' do it 'generates the correct mutations' do

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Reporter::CLI do
describe Mutant::Reporter::CLI do
let(:object) { described_class.new(output) } let(:object) { described_class.new(output) }
let(:output) { StringIO.new } let(:output) { StringIO.new }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Reporter::Null do
describe Mutant::Reporter::Null do
let(:object) { described_class.new } let(:object) { described_class.new }
describe '#report' do describe '#report' do

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::RequireHighjack do
describe Mutant::RequireHighjack do
let(:object) { described_class.new(target, highjacked_calls.method(:push)) } let(:object) { described_class.new(target, highjacked_calls.method(:push)) }
let(:highjacked_calls) { [] } let(:highjacked_calls) { [] }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
class Double class Double
include Concord.new(:name, :attributes) include Concord.new(:name, :attributes)
@ -19,7 +17,7 @@ class Double
end end
# FIXME: This is not even close to a mutation covering spec. # FIXME: This is not even close to a mutation covering spec.
describe Mutant::Runner do RSpec.describe Mutant::Runner do
let(:object) { described_class.new(env) } let(:object) { described_class.new(env) }
let(:reporter) { Mutant::Reporter::Trace.new } let(:reporter) { Mutant::Reporter::Trace.new }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Subject, '#context' do
describe Mutant::Subject, '#context' do
subject { object.context } subject { object.context }
let(:class_under_test) do let(:class_under_test) do

View file

@ -1,8 +1,4 @@
# encoding: UTF-8 RSpec.describe Mutant::Subject::Method::Instance do
require 'spec_helper'
describe Mutant::Subject::Method::Instance do
let(:object) { described_class.new(config, context, node) } let(:object) { described_class.new(config, context, node) }
let(:context) { double } let(:context) { double }
let(:config) { Mutant::Config::DEFAULT } let(:config) { Mutant::Config::DEFAULT }
@ -71,7 +67,7 @@ describe Mutant::Subject::Method::Instance do
end end
end end
describe Mutant::Subject::Method::Instance::Memoized do RSpec.describe Mutant::Subject::Method::Instance::Memoized do
let(:object) { described_class.new(config, context, node) } let(:object) { described_class.new(config, context, node) }
let(:context) { double } let(:context) { double }
let(:config) { Mutant::Config::DEFAULT } let(:config) { Mutant::Config::DEFAULT }

View file

@ -1,8 +1,4 @@
# encoding: UTF-8 RSpec.describe Mutant::Subject::Method::Singleton do
require 'spec_helper'
describe Mutant::Subject::Method::Singleton do
let(:object) { described_class.new(config, context, node) } let(:object) { described_class.new(config, context, node) }
let(:config) { Mutant::Config::DEFAULT } let(:config) { Mutant::Config::DEFAULT }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Subject do
describe Mutant::Subject do
let(:class_under_test) do let(:class_under_test) do
Class.new(described_class) do Class.new(described_class) do
def expression def expression

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::Test do
describe Mutant::Test do
let(:object) { described_class.new(integration, expression) } let(:object) { described_class.new(integration, expression) }
let(:integration) { double('Integration', name: 'test-integration') } let(:integration) { double('Integration', name: 'test-integration') }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::WarningExpectation do
describe Mutant::WarningExpectation do
let(:object) { described_class.new(expected_warnings) } let(:object) { described_class.new(expected_warnings) }
let(:expected_warnings) { [] } let(:expected_warnings) { [] }

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant::WarningFilter do
describe Mutant::WarningFilter do
before do before do
if RUBY_ENGINE.eql?('rbx') if RUBY_ENGINE.eql?('rbx')
skip 'Disabled because expected warnings are from MRI' skip 'Disabled because expected warnings are from MRI'

View file

@ -1,6 +1,4 @@
require 'spec_helper' RSpec.describe Mutant do
describe Mutant do
let(:object) { described_class } let(:object) { described_class }
describe '.zombify' do describe '.zombify' do

View file

@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe TestApp::Literal, '#string' do RSpec.describe TestApp::Literal, '#string' do
subject { object.string } subject { object.string }
let(:object) { described_class.new } let(:object) { described_class.new }