SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Let's begin Behavior Driven Development using RSpec
18.
module System
class AgeCalculatorTest < Test::Unit::TestCase
include RR::Adapters::TestUnit
def setup
@calc = AgeCalculator.with_birthday(1981, 7, 20)
end
def test_age_on
assert_equal(29, @calc.age_on(2011, 7, 19))
assert_equal(30, @calc.age_on(2011, 7, 20))
end
def test_age_today
d, m, y = [*Time.now][3..5]
stub(@calc).age_on
@calc.age_on_today
assert_received(@calc) {|c| c.age_on(y, m, d) }
end
end
end
2011 5 22
20.
module System
describe AgeCalculator do
context ‘with birthday 1981-07-20’ do
subject { AgeCalculator.with_birthday(1981, 7, 20) }
describe ‘#age_on’ do
context ‘with 2011-07-19’ do
specify ‘the age is 29’ do
subject.age_on(2011, 7, 19).should be == 29
end
end
context ‘with 2011-07-20’ do
specify ‘the age is 30’ do
subject.age_on(2011, 7, 20).should be == 30
end
end
end
describe ‘#age_on_today’ do
it ‘calls age_on with year, month, and day on today’ do
d, m, y = [*Time.now][3..5]
subject.should_receive(:age_on).with(y, m, d)
subject.age_on_today
end
end
end
end
end
2011 5 22
34.
module System
describe AgeCalculator do
context ‘with birthday 1981-07-20’ do
subject { AgeCalculator.with_birthday(1981, 7, 20) }
describe ‘#age_on’ do
context ‘with 2011-07-19’ do
specify ‘the age is 29’ do
subject.age_on(2011, 7, 19).should be == 29
end
end
context ‘with 2011-07-20’ do
specify ‘the age is 30’ do
subject.age_on(2011, 7, 20).should be == 30
end
end
end
describe ‘#age_on_today’ do
it ‘calls age_on with year, month, and day on today’ do
d, m, y = [*Time.now][3..5]
subject.should_receive(:age_on).with(y, m, d)
subject.age_on_today
end
end
end
end
end
2011 5 22
62.
Photo by rla579: http://flickr.com/photos/rla579/2482286520/
2011 5 22
63.
Working Effectively with Legacy tDiary Code
using Cucumber and RSpec
KAKUTANI Shintaro; Eiwa System Management,Inc.; Nihon Ruby-no-kai
http://kakutani.com/articles/working_effectively_with_legacy_tdiary_code_using_cucumber_and_rspec.pdf
2011 5 22
75.
RSpec Best Practice
http://jp.rubyist.net/magazine/?0032-TranslationArticle
2011 5 22
76.
describe FizzBuzzCounter do
describe ‘.filter’ do
context ‘with 1’ do
it ‘returns 1’ do
FizzBuzzCounter.
filter(1).should be == 1
end
end
end
end
2011 5 22
77.
describe FizzBuzzCounter do
describe ‘.filter’ do
context ‘with 1’ do
it ‘returns 1’ do
FizzBuzzCounter.
filter(1).should be == 1
end
end
end
end
2011 5 22
85.
describe ConcreteObservable do
describe ‘#change’ do
it ‘calls its notify()’ do
subject.should_receive(:notify)
subject.change
end
end
end
2011 5 22
86.
describe ConcreteObservable do
describe ‘#change’ do
subject { ConcreteObservable.new }
it “calls observers’ update()” do
observer = double(‘an observer’)
observer.should_receive(:update)
subject.change
end
end
end
2011 5 22