Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created May 7, 2010 10:11
Show Gist options
  • Save chrisroos/393255 to your computer and use it in GitHub Desktop.
Save chrisroos/393255 to your computer and use it in GitHub Desktop.
Example tests and the equivalent specs
gem 'rspec'
class Person
attr_reader :forename, :surname
def initialize(forename, surname)
@forename, @surname = forename, surname
end
def name_complete?
forename && surname
end
end
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
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
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