Created
May 7, 2010 10:11
-
-
Save chrisroos/393255 to your computer and use it in GitHub Desktop.
Example tests and the equivalent specs
This file contains hidden or 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
gem 'rspec' |
This file contains hidden or 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
class Person | |
attr_reader :forename, :surname | |
def initialize(forename, surname) | |
@forename, @surname = forename, surname | |
end | |
def name_complete? | |
forename && surname | |
end | |
end |
This file contains hidden or 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
require 'person' | |
require 'spec' | |
describe Person do | |
it 'should indicate that the name is complete' do | |
person = Person.new('chris', 'roos') | |
person.name_complete?.should_not be_false | |
end | |
it 'should indicate that the name is incomplete when the forename is missing' do | |
person = Person.new(nil, 'roos') | |
person.name_complete?.should_not be_true | |
end | |
it 'should indicate that the name is incomplete when the surname is missing' do | |
person = Person.new('chris', nil) | |
person.name_complete?.should_not be_true | |
end | |
end |
This file contains hidden or 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
require 'person' | |
require 'test/unit' | |
class PersonTest < Test::Unit::TestCase | |
def test_should_indicate_that_the_name_is_complete | |
person = Person.new('chris', 'roos') | |
assert person.name_complete? | |
end | |
def test_should_indicate_that_the_name_is_incomplete_when_the_forename_is_missing | |
person = Person.new(nil, 'roos') | |
assert_not_equal true, person.name_complete? | |
end | |
def test_should_indicate_that_the_name_is_incomplete_when_the_surname_is_missing | |
person = Person.new('chris', nil) | |
assert_not_equal true, person.name_complete? | |
end | |
end |
This file contains hidden or 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
require 'rake/testtask' | |
require 'spec/rake/spectask' | |
task :default => [:test, :examples] | |
Rake::TestTask.new(:test) do |t| | |
t.test_files = FileList['*_test.rb'] | |
t.verbose = true | |
end | |
Spec::Rake::SpecTask.new(:examples) do |t| | |
t.spec_files = FileList['*_spec.rb'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment