forked from burke/zeus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request burke#364 from sideshowcoder/test_cleanup_constant…
…_assignment Don't reassign Runner constant
- Loading branch information
Showing
1 changed file
with
68 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,110 @@ | ||
require 'spec_helper' | ||
require 'fake_mini_test' | ||
|
||
describe Zeus::M::Runner do | ||
Runner = Zeus::M::Runner | ||
module Zeus::M | ||
describe Runner do | ||
|
||
context "given a test with a question mark" do | ||
before do | ||
MiniTest::Unit::TestCase.stub!(:test_suites).and_return [fake_suite_with_special_characters] | ||
MiniTest::Unit.stub!(:runner).and_return fake_runner | ||
end | ||
context "given a test with a question mark" do | ||
before do | ||
MiniTest::Unit::TestCase.stub!(:test_suites).and_return [fake_suite_with_special_characters] | ||
MiniTest::Unit.stub!(:runner).and_return fake_runner | ||
end | ||
|
||
it "escapes the question mark when using line number" do | ||
argv = ["path/to/file.rb:2"] | ||
it "escapes the question mark when using line number" do | ||
argv = ["path/to/file.rb:2"] | ||
|
||
fake_runner.should_receive(:run).with(["-n", "/(test_my_test_method\\?)/"]) | ||
fake_runner.should_receive(:run).with(["-n", "/(test_my_test_method\\?)/"]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
|
||
it "escapes the question mark from explicit names" do | ||
argv = ["path/to/file.rb", "--name", fake_special_characters_test_method] | ||
it "escapes the question mark from explicit names" do | ||
argv = ["path/to/file.rb", "--name", fake_special_characters_test_method] | ||
|
||
fake_runner.should_receive(:run).with(["-n", "test_my_test_method\\?"]) | ||
fake_runner.should_receive(:run).with(["-n", "test_my_test_method\\?"]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe Zeus::M::Runner do | ||
Runner = Zeus::M::Runner | ||
|
||
before do | ||
stub_mini_test_methods | ||
end | ||
describe Runner do | ||
before do | ||
stub_mini_test_methods | ||
end | ||
|
||
context "no option is given" do | ||
it "runs the test without giving any option" do | ||
argv = ["path/to/file.rb"] | ||
context "no option is given" do | ||
it "runs the test without giving any option" do | ||
argv = ["path/to/file.rb"] | ||
|
||
fake_runner.should_receive(:run).with([]) | ||
fake_runner.should_receive(:run).with([]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
end | ||
end | ||
|
||
context "given a line number" do | ||
it "aborts if no test is found" do | ||
argv = ["path/to/file.rb:100"] | ||
context "given a line number" do | ||
it "aborts if no test is found" do | ||
argv = ["path/to/file.rb:100"] | ||
|
||
STDERR.should_receive(:write).with(/No tests found on line 100/) | ||
fake_runner.should_not_receive :run | ||
STDERR.should_receive(:write).with(/No tests found on line 100/) | ||
fake_runner.should_not_receive :run | ||
|
||
lambda { Runner.new(argv).run }.should_not exit_with_code(0) | ||
end | ||
lambda { Runner.new(argv).run }.should_not exit_with_code(0) | ||
end | ||
|
||
it "runs the test if the correct line number is given" do | ||
argv = ["path/to/file.rb:2"] | ||
it "runs the test if the correct line number is given" do | ||
argv = ["path/to/file.rb:2"] | ||
|
||
fake_runner.should_receive(:run).with(["-n", "/(#{fake_test_method})/"]) | ||
fake_runner.should_receive(:run).with(["-n", "/(#{fake_test_method})/"]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
end | ||
end | ||
|
||
context "specifying test name" do | ||
it "runs the specified tests when using a pattern in --name option" do | ||
argv = ["path/to/file.rb", "--name", "/#{fake_test_method}/"] | ||
context "specifying test name" do | ||
it "runs the specified tests when using a pattern in --name option" do | ||
argv = ["path/to/file.rb", "--name", "/#{fake_test_method}/"] | ||
|
||
fake_runner.should_receive(:run).with(["-n", "/#{fake_test_method}/"]) | ||
fake_runner.should_receive(:run).with(["-n", "/#{fake_test_method}/"]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
|
||
it "runs the specified tests when using a pattern in -n option" do | ||
argv = ["path/to/file.rb", "-n", "/method/"] | ||
it "runs the specified tests when using a pattern in -n option" do | ||
argv = ["path/to/file.rb", "-n", "/method/"] | ||
|
||
fake_runner.should_receive(:run).with(["-n", "/method/"]) | ||
fake_runner.should_receive(:run).with(["-n", "/method/"]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
|
||
it "aborts if no test matches the given pattern" do | ||
argv = ["path/to/file.rb", "-n", "/garbage/"] | ||
it "aborts if no test matches the given pattern" do | ||
argv = ["path/to/file.rb", "-n", "/garbage/"] | ||
|
||
STDERR.should_receive(:write).with(%r{No test name matches \'/garbage/\'}) | ||
fake_runner.should_not_receive :run | ||
STDERR.should_receive(:write).with(%r{No test name matches \'/garbage/\'}) | ||
fake_runner.should_not_receive :run | ||
|
||
lambda { Runner.new(argv).run }.should_not exit_with_code(0) | ||
end | ||
lambda { Runner.new(argv).run }.should_not exit_with_code(0) | ||
end | ||
|
||
it "runs the specified tests when using a name (no pattern)" do | ||
argv = ["path/to/file.rb", "-n", "#{fake_test_method}"] | ||
it "runs the specified tests when using a name (no pattern)" do | ||
argv = ["path/to/file.rb", "-n", "#{fake_test_method}"] | ||
|
||
fake_runner.should_receive(:run).with(["-n", fake_test_method]) | ||
fake_runner.should_receive(:run).with(["-n", fake_test_method]) | ||
|
||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
lambda { Runner.new(argv).run }.should exit_with_code(0) | ||
end | ||
|
||
it "aborts if no test matches the given test name" do | ||
argv = ["path/to/file.rb", "-n", "method"] | ||
it "aborts if no test matches the given test name" do | ||
argv = ["path/to/file.rb", "-n", "method"] | ||
|
||
STDERR.should_receive(:write).with(%r{No test name matches \'method\'}) | ||
fake_runner.should_not_receive :run | ||
STDERR.should_receive(:write).with(%r{No test name matches \'method\'}) | ||
fake_runner.should_not_receive :run | ||
|
||
lambda { Runner.new(argv).run }.should_not exit_with_code(0) | ||
lambda { Runner.new(argv).run }.should_not exit_with_code(0) | ||
end | ||
end | ||
end | ||
|
||
end |