Skip to content

Commit

Permalink
Fix all style warnings under spec/**/*.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jul 28, 2013
1 parent b087a6e commit 46f90aa
Show file tree
Hide file tree
Showing 25 changed files with 292 additions and 139 deletions.
12 changes: 12 additions & 0 deletions config/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ Documentation:
IfUnlessModifier:
Enabled: false

# Mutant needs to define methods like def bar; end in specs
Semicolon:
Enabled: false

# Mutant needs to define multiple methods on same line in specs
EmptyLineBetweenDefs:
Enabled: false

# Mutant needs to define singleton methods like Foo.bar in specs
ClassMethods:
Enabled: false

# Allow case equality operator (in limited use within the specs)
CaseEquality:
Enabled: false
Expand Down
9 changes: 6 additions & 3 deletions spec/integration/mutant/rspec_killer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
let(:strategy) { Mutant::Strategy::Rspec::DM2 }

specify 'allows to kill mutations' do
Kernel.system('bundle exec mutant --rspec-dm2 ::TestApp::Literal#string').should be(true)
cli = 'bundle exec mutant --rspec-dm2 ::TestApp::Literal#string'
Kernel.system(cli).should be(true)
end

specify 'fails to kill mutations when they are not covered' do
Kernel.system('bundle exec mutant --rspec-dm2 ::TestApp::Literal#uncovered_string').should be(false)
cli = 'bundle exec mutant --rspec-dm2 ::TestApp::Literal#uncovered_string'
Kernel.system(cli).should be(false)
end

specify 'fails when some mutations when are not covered' do
Kernel.system('bundle exec mutant --rspec-dm2 ::TestApp::Literal').should be(false)
cli = 'bundle exec mutant --rspec-dm2 ::TestApp::Literal'
Kernel.system(cli).should be(false)
end
end
17 changes: 13 additions & 4 deletions spec/shared/mutator_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def assert_transitive!
again = Unparser.generate(parsed)
unless generated == again
# mostly an unparser bug!
fail "Untransitive:\n%s\n---\n%s" % [generated, again]
fail sprintf("Untransitive:\n%s\n---\n%s", generated, again)
end
self
end
Expand Down Expand Up @@ -74,16 +74,25 @@ def assert_transitive!
message = []

if missing.any?
message << 'Missing mutations (%i):' % missing.length
message << sprintf('Missing mutations (%i):', missing.length)
message.concat(missing)
end

if unexpected.any?
message << 'Unexpected mutations (%i):' % unexpected.length
message << sprintf('Unexpected mutations (%i):', unexpected.length)
message.concat(unexpected)
end

fail "Original:\n#{generate(node)}\n-----\n#{message.join("\n-----\n")}" if message.any?
if message.any?

message = sprintf(
"Original:\n%s\n-----\n%s",
generate(node),
message.join("\n-----\n")
)

fail message
end
end
end
end
Expand Down
23 changes: 15 additions & 8 deletions spec/unit/mutant/cli/class_methods/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

shared_examples_for 'an invalid cli run' do
it 'should raise error' do
expect { subject }.to raise_error(Mutant::CLI::Error, expected_message)
expect do
subject
end.to raise_error(Mutant::CLI::Error, expected_message)
end
end

Expand All @@ -28,6 +30,9 @@
let(:expected_strategy) { Mutant::Strategy::Rspec::Unit }
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }

let(:ns) { Mutant::CLI::Classifier }
let(:cache) { Mutant::Cache.new }

let(:cli) { object.new(arguments) }

subject { cli }
Expand Down Expand Up @@ -70,21 +75,23 @@
end

context 'with explicit method matcher' do
let(:arguments) { %w(--rspec-unit TestApp::Literal#float) }
let(:expected_matcher) { Mutant::CLI::Classifier::Method.new(Mutant::Cache.new, 'TestApp::Literal#float') }
let(:arguments) { %w(--rspec-unit TestApp::Literal#float) }
let(:expected_matcher) { ns::Method.new(cache, 'TestApp::Literal#float') }

it_should_behave_like 'a cli parser'
end

context 'with namespace matcher' do
let(:arguments) { %w(--rspec-unit ::TestApp*) }
let(:expected_matcher) { Mutant::CLI::Classifier::Namespace::Recursive.new(Mutant::Cache.new, '::TestApp*') }
let(:matcher) { '::TestApp*' }
let(:arguments) { %W(--rspec-unit #{matcher}) }
let(:expected_matcher) { ns::Namespace::Recursive.new(cache, matcher) }

it_should_behave_like 'a cli parser'
end

context 'with code filter' do
let(:arguments) { %w(--rspec-unit --code faa --code bbb TestApp::Literal#float) }
let(:matcher) { 'TestApp::Literal#float' }
let(:arguments) { %W(--rspec-unit --code faa --code bbb #{matcher}) }

let(:filters) do
[
Expand All @@ -93,8 +100,8 @@
]
end

let(:expected_matcher) { Mutant::CLI::Classifier::Method.new(Mutant::Cache.new, 'TestApp::Literal#float') }
let(:expected_filter) { Mutant::Mutation::Filter::Whitelist.new(filters) }
let(:expected_matcher) { ns::Method.new(cache, 'TestApp::Literal#float') }
let(:expected_filter) { Mutant::Mutation::Filter::Whitelist.new(filters) }

it_should_behave_like 'a cli parser'
end
Expand Down
10 changes: 8 additions & 2 deletions spec/unit/mutant/cli/class_methods/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
it { should be(0) }

it 'should run with attributes' do
Mutant::Runner::Config.should_receive(:run).with(config).and_return(runner)
Mutant::Runner::Config
.should_receive(:run)
.with(config)
.and_return(runner)
should be(0)
end
end
Expand All @@ -32,7 +35,10 @@
it { should be(1) }

it 'should run with attributes' do
Mutant::Runner::Config.should_receive(:run).with(config).and_return(runner)
Mutant::Runner::Config
.should_receive(:run)
.with(config)
.and_return(runner)
should be(1)
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/mutant/cli/classifier/class_methods/build_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

shared_examples_for this_spec do
it 'shoud return expected instance' do
should eql(expected_class.new(cache, expected_class::REGEXP.match(input)))
regexp = expected_class::REGEXP
should eql(expected_class.new(cache, regexp.match(input)))
end

let(:expected_class) { Mutant::CLI::Classifier::Method }
Expand Down
4 changes: 3 additions & 1 deletion spec/unit/mutant/context/root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
let(:object) { described_class.allocate }

it 'should raise error' do
expect { subject }.to raise_error('Mutant::Context#root is not implemented')
expect do
subject
end.to raise_error('Mutant::Context#root is not implemented')
end
end
70 changes: 65 additions & 5 deletions spec/unit/mutant/differ/diff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
let(:old) { %w(foo bar) }
let(:new) { %w(baz bar) }

it { should eql("@@ -1,3 +1,3 @@\n-foo\n+baz\n bar\n") }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,3 +1,3 @@
-foo
+baz
bar
STR
end

it { should eql(expectation) }

it_should_behave_like 'an idempotent method'
end
Expand All @@ -18,7 +27,16 @@
let(:old) { %w(foo bar) }
let(:new) { %w(foo baz bar) }

it { should eql("@@ -1,3 +1,4 @@\n foo\n+baz\n bar\n") }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,3 +1,4 @@
foo
+baz
bar
STR
end

it { should eql(expectation) }

it_should_behave_like 'an idempotent method'
end
Expand All @@ -27,7 +45,21 @@
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c other) }

it { should eql("@@ -1,8 +1,9 @@\n foo\n bar\n baz\n boz\n a\n b\n c\n+other\n") }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,8 +1,9 @@
foo
bar
baz
boz
a
b
c
+other
STR
end

it { should eql(expectation) }

it_should_behave_like 'an idempotent method'
end
Expand All @@ -36,7 +68,21 @@
let(:old) { %w(other foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c) }

it { should eql("@@ -1,9 +1,8 @@\n-other\n foo\n bar\n baz\n boz\n a\n b\n c\n") }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,9 +1,8 @@
-other
foo
bar
baz
boz
a
b
c
STR
end

it { should eql(expectation) }

it_should_behave_like 'an idempotent method'
end
Expand All @@ -45,7 +91,21 @@
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(other foo bar baz boz a b c) }

it { should eql("@@ -1,8 +1,9 @@\n+other\n foo\n bar\n baz\n boz\n a\n b\n c\n") }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,8 +1,9 @@
+other
foo
bar
baz
boz
a
b
c
STR
end

it { should eql(expectation) }

it_should_behave_like 'an idempotent method'
end
Expand Down
23 changes: 19 additions & 4 deletions spec/unit/mutant/killer/rspec/class_methods/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@

subject { object.new(strategy, mutation) }

let(:strategy) { double('Strategy', :spec_files => ['foo'], :error_stream => $stderr, :output_stream => $stdout) }
let(:context) { double('Context') }
let(:mutation) { double('Mutation', :subject => mutation_subject, :should_survive? => false) }
let(:mutation_subject) { double('Mutation Subject') }
let(:context) { double('Context') }
let(:mutation_subject) { double('Mutation Subject') }

let(:object) { described_class }

let(:mutation) do
double(
'Mutation',
:subject => mutation_subject,
:should_survive? => false
)
end

let(:strategy) do
double(
'Strategy',
:spec_files => ['foo'],
:error_stream => $stderr,
:output_stream => $stdout
)
end

before do
mutation.stub(:insert)
mutation.stub(:reset)
Expand Down
15 changes: 10 additions & 5 deletions spec/unit/mutant/loader/eval/class_methods/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

subject { object.run(node, mutation_subject) }

let(:object) { described_class }
let(:mutation_subject) { double('Subject', :source_path => path, :source_line => line) }
let(:path) { 'test.rb' }
let(:line) { 1 }
let(:object) { described_class }
let(:path) { 'test.rb' }
let(:line) { 1 }

let(:mutation_subject) do
double('Subject', :source_path => path, :source_line => line)
end

let(:source) do
<<-RUBY
Expand Down Expand Up @@ -36,6 +39,8 @@ class Foo < Bar

it 'should set file and line correctly' do
subject
::SomeNamespace::Bar.instance_method(:some_method).source_location.should eql(['test.rb', 3])
::SomeNamespace::Bar
.instance_method(:some_method)
.source_location.should eql(['test.rb', 3])
end
end
7 changes: 6 additions & 1 deletion spec/unit/mutant/matcher/each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
let(:object) { described_class.allocate }

it 'should raise error' do
expect { subject }.to raise_error(NotImplementedError, 'Mutant::Matcher#each is not implemented')
expect do
subject
end.to raise_error(
NotImplementedError,
'Mutant::Matcher#each is not implemented'
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def bar
context 'with unmemoized method' do
let(:method_name) { :bar }

it { should eql(Mutant::Matcher::Method::Instance.new(cache, scope, method)) }
it { should eql(described_class.new(cache, scope, method)) }
end

context 'with memoized method' do
let(:method_name) { :foo }

it { should eql(Mutant::Matcher::Method::Instance::Memoized.new(cache, scope, method)) }
it { should eql(described_class::Memoized.new(cache, scope, method)) }
end
end
end
Loading

0 comments on commit 46f90aa

Please sign in to comment.