Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Greg
committed
Aug 9, 2009
0 parents
commit d38c501
Showing
5 changed files
with
151 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
|
||
task :default => [:test] | ||
|
||
desc 'Run all unit, functional and integration tests' | ||
task :test do | ||
errors = %w(test:units test:functionals test:integration).collect do |task| | ||
begin | ||
Rake::Task[task].invoke | ||
nil | ||
rescue => e | ||
task | ||
end | ||
end.compact | ||
abort "Errors running #{errors}!" if errors.any? | ||
end | ||
|
||
namespace :test do | ||
Rake::TestTask.new(:units) do |t| | ||
t.libs << "test" | ||
t.pattern = 'test/unit/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
Rake::Task['test:units'].comment = "Run the unit tests in test/unit" | ||
|
||
Rake::TestTask.new(:functionals) do |t| | ||
t.libs << "test" | ||
t.pattern = 'test/functional/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional" | ||
|
||
Rake::TestTask.new(:integration) do |t| | ||
t.libs << "test" | ||
t.pattern = 'test/integration/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
Rake::Task['test:integration'].comment = "Run the integration tests in test/integration" | ||
end |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
require File.dirname(__FILE__) + '/go_fish' | ||
|
||
puts GoFish.fish_today? |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class GoFish | ||
|
||
@@positive_response = "Go fish" | ||
@@negative_response = "Hack" | ||
@@fishing_forecaster = "" | ||
|
||
def self.positive_response | ||
@@positive_response | ||
end | ||
|
||
def self.positive_response=(response) | ||
@@positive_response = response | ||
end | ||
|
||
def self.negative_response | ||
@@negative_response | ||
end | ||
|
||
def self.negative_response=(response) | ||
@@negative_response = response | ||
end | ||
|
||
def self.fishing_forecaster | ||
@@fishing_forecaster | ||
end | ||
|
||
def self.fishing_forecaster=(forecaster) | ||
@@fishing_forecaster = forecaster | ||
end | ||
|
||
def self.fish_today? | ||
fishing_forecaster.fishibility >= 0.5 ? positive_response : negative_response | ||
end | ||
|
||
end |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rubygems' | ||
require 'test/unit' | ||
require 'mocha' | ||
|
||
require File.dirname(__FILE__) + '/../go_fish' |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require File.dirname(__FILE__) + '/../test_helper' | ||
|
||
class GoFishTest < Test::Unit::TestCase | ||
|
||
def setup | ||
assert @positive_response = GoFish.positive_response | ||
assert @negative_response = GoFish.negative_response | ||
assert_not_equal @positive_response, @negative_response | ||
end | ||
|
||
def teardown | ||
end | ||
|
||
def test_lt_50_percent_fishibility | ||
fishibility = 0.49 | ||
GoFish.fishing_forecaster = stub(:fishibility => fishibility) | ||
assert_negative_response GoFish.fish_today? | ||
end | ||
|
||
def test_eq_50_percent_fishibility | ||
fishibility = 0.50 | ||
GoFish.fishing_forecaster = stub(:fishibility => fishibility) | ||
assert_positive_response GoFish.fish_today? | ||
end | ||
|
||
def test_gt_50_percent_fishibility | ||
fishibility = 0.51 | ||
GoFish.fishing_forecaster = stub(:fishibility => fishibility) | ||
assert_positive_response GoFish.fish_today? | ||
end | ||
|
||
def test_fishing_forecaster_getter_setter | ||
fishing_forecaster = dummy_object | ||
assert_not_equal fishing_forecaster, GoFish.fishing_forecaster | ||
GoFish.fishing_forecaster = fishing_forecaster | ||
assert_equal fishing_forecaster, GoFish.fishing_forecaster | ||
end | ||
|
||
def test_positive_response_getter_setter | ||
response = 'yes' | ||
assert_not_equal response, GoFish.positive_response | ||
GoFish.positive_response = response | ||
assert_equal response, GoFish.positive_response | ||
end | ||
|
||
def test_negative_response_getter_setter | ||
response = 'no' | ||
assert_not_equal response, GoFish.negative_response | ||
GoFish.negative_response = response | ||
assert_equal response, GoFish.negative_response | ||
end | ||
|
||
private | ||
|
||
def dummy_object | ||
Object.new | ||
end | ||
|
||
def assert_positive_response(response) | ||
assert_equal @positive_response, response | ||
end | ||
|
||
def assert_negative_response(response) | ||
assert_equal @negative_response, response | ||
end | ||
|
||
end |