Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg committed Aug 9, 2009
0 parents commit d38c501
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Rakefile
@@ -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
4 changes: 4 additions & 0 deletions go_fish
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/go_fish'

puts GoFish.fish_today?
35 changes: 35 additions & 0 deletions go_fish.rb
@@ -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
5 changes: 5 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,5 @@
require 'rubygems'
require 'test/unit'
require 'mocha'

require File.dirname(__FILE__) + '/../go_fish'
67 changes: 67 additions & 0 deletions test/unit/go_fish_test.rb
@@ -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

0 comments on commit d38c501

Please sign in to comment.