Skip to content

Commit

Permalink
Don't pass configuration around, just the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
iain committed Jun 16, 2012
1 parent 6a32f3a commit 64b983e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/test_suite/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CLI < Thor

desc "go", "Runs your test suite"
def go
runner = Runner.call(TestSuite.configuration)
runner = Runner.call(TestSuite.configuration.commands)
exit runner.exit_status
end

Expand Down
14 changes: 5 additions & 9 deletions lib/test_suite/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
module TestSuite
class Report

def self.call(configuration)
report = new(configuration)
def self.call(commands)
report = new(commands)
report.call
report
end

attr_reader :configuration
attr_reader :commands

def initialize(configuration)
@configuration = configuration
end

def commands
configuration.commands
def initialize(commands)
@commands = commands
end

def call
Expand Down
16 changes: 8 additions & 8 deletions lib/test_suite/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
module TestSuite
class Runner

def self.call(configuration)
runner = new(configuration)
def self.call(commands)
runner = new(commands)
runner.call
runner
end

attr_reader :configuration
attr_reader :commands

def initialize(configuration)
@configuration = configuration
def initialize(commands)
@commands = commands
end

def call
configuration.commands.each(&:run!)
commands.each(&:run!)
rescue CommandFailed => error
ensure
Report.call(configuration)
Report.call(commands)
end

def exit_status
configuration.commands.all?(&:ok?) ? 0 : 1
commands.all?(&:ok?) ? 0 : 1
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/test_suite/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it "runs the tests" do
TestSuite::Runner.should_receive(:call).with(TestSuite.configuration)
TestSuite::Runner.should_receive(:call).with(TestSuite.configuration.commands)
subject.go
end

Expand Down
7 changes: 3 additions & 4 deletions spec/test_suite/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
end

it "prints out a report" do
ls = stub :ls, :name => :ls, :runtime => 0.4, :status => "success"
foobar = stub :foobar, :name => :foobar, :runtime => 1.4, :status => "failed"
configuration = stub :commands => [ ls, foobar ]
TestSuite::Report.call(configuration)
ls = stub :ls, :name => :ls, :runtime => 0.4, :status => "success"
foobar = stub :foobar, :name => :foobar, :runtime => 1.4, :status => "failed"
TestSuite::Report.call([ls, foobar])
stderr.rewind
stderr.read.should eq <<-DOC
┌─────────┬─────────┬─────────┐
Expand Down
24 changes: 9 additions & 15 deletions spec/test_suite/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,45 @@
TestSuite::Report.stub(:call)
end

it "runs a certain configuration" do
it "runs a certain set of commands" do
command = stub :command
configuration = stub :configuration, :commands => [ command ]
command.should_receive(:run!)
TestSuite::Runner.call(configuration)
TestSuite::Runner.call([command])
end

it "may be halted immediately, due to a failed command" do
failing_command = stub :failing_command
next_command = stub :next_command
configuration = stub :configuration, :commands => [ failing_command, next_command ]
failing_command.stub(:run!) { raise TestSuite::CommandFailed, "some reason" }
next_command.should_not_receive(:run!)
TestSuite::Runner.call(configuration)
TestSuite::Runner.call([failing_command, next_command])
end

it "has exit status 0 when everycommand went ok" do
command = stub :command, :run! => true
configuration = stub :configuration, :commands => [ command ]
command.should_receive(:ok?).and_return(true)
runner = TestSuite::Runner.call(configuration)
runner = TestSuite::Runner.call([command])
runner.exit_status.should be 0
end

it "has exit status 1 when a command failed" do
command = stub :command, :run! => true
configuration = stub :configuration, :commands => [ command ]
command.should_receive(:ok?).and_return(false)
runner = TestSuite::Runner.call(configuration)
runner = TestSuite::Runner.call([command])
runner.exit_status.should be 1
end

it "reports the status of the commands" do
command = stub :command, :run! => true
configuration = stub :configuration, :commands => [ command ]
TestSuite::Report.should_receive(:call).with(configuration)
TestSuite::Runner.call(configuration)
TestSuite::Report.should_receive(:call).with([command])
TestSuite::Runner.call([command])
end

it "also reports the status when the build was halted" do
command = stub :command
configuration = stub :configuration, :commands => [ command ]
command.stub(:run!) { raise TestSuite::CommandFailed, "some reason" }
TestSuite::Report.should_receive(:call).with(configuration)
TestSuite::Runner.call(configuration)
TestSuite::Report.should_receive(:call).with([command])
TestSuite::Runner.call([command])
end


Expand Down

0 comments on commit 64b983e

Please sign in to comment.