7. Why Testing?
In Agile Development
• We are testing
repeatedly.
• Small team without
specialist.
(c)2012 YourGolf Online Inc. All Rights Reserved.
8. Why Testing?
In Agile Development
Analyst
• We are testing Tester Developer
repeatedly.
• Small team without
specialist. Analyst
Tester Developer
(c)2012 YourGolf Online Inc. All Rights Reserved.
9. Why Ruby?
• Ruby community is high-quality and
active community.
• So, there are a lot of useful testing
libraries and tools.
(c)2012 YourGolf Online Inc. All Rights Reserved.
10. Top Languages on github
(c)2012 YourGolf Online Inc. All Rights Reserved.
11. Top Languages on github
(c)2012 YourGolf Online Inc. All Rights Reserved.
12. Why Ruby?
• Ruby community is high-quality and active
community.
• So, there are a lot of useful testing
libraries and tools.
(c)2012 YourGolf Online Inc. All Rights Reserved.
13. Libraries and Tools
• Rspec
• Timecop
• Factory Girl
• Capybara, Capybara-webkit
• VCR
(c)2012 YourGolf Online Inc. All Rights Reserved.
14. Timecop
• It provides "time travel" and "time freezing"
capabilities, making it dead simple to test time-
dependent code.
(c)2012 YourGolf Online Inc. All Rights Reserved.
15. Timecop
• It provides "time travel" and "time freezing"
capabilities, making it dead simple to test time-
dependent code.
$ sudo date 021423002005
(c)2012 YourGolf Online Inc. All Rights Reserved.
16. Timecop
• It provides "time travel" and "time freezing"
capabilities, making it dead simple to test time-
dependent code.
$ sudo date 021423002005
He should use Timecop!
(c)2012 YourGolf Online Inc. All Rights Reserved.
17. Timecop
describe "API rate limit" do
context "when accessed more than 100 times" do
before do
@rate_limit = Factory.create(:rate_limit, count: 101)
end
it "will be not available" do
@rate_limit.exceeded?.should be_true
end
it "can be reseted after 1 hour" do
Timecop.travel(Time.now + 1.hours + 1.minutes)
@rate_limit.exceeded?.should be_false
end
end
end
(c)2012 YourGolf Online Inc. All Rights Reserved.
18. Timecop
describe "API rate limit" do
context "when accessed more than 100 times" do
before do
@rate_limit = Factory.create(:rate_limit, count: 101)
end
it "will be not available" do
@rate_limit.exceeded?.should be_true
end
it "can be reseted after 1 hour" do
Timecop.travel(Time.now + 1.hours + 1.minutes)
@rate_limit.exceeded?.should be_false
end
end
end
(c)2012 YourGolf Online Inc. All Rights Reserved.
19. Timecop
describe "API rate limit" do
context "when accessed more than 100 times" do
before do
@rate_limit = Factory.create(:rate_limit, count: 101)
end
it "will be not available" do
@rate_limit.exceeded?.should be_true
end
it "can be reseted after 1 hour" do
Timecop.travel(Time.now + 1.hours + 1.minutes)
@rate_limit.exceeded?.should be_false
end
end
end
(c)2012 YourGolf Online Inc. All Rights Reserved.
20. Timecop
describe "API rate limit" do
context "when accessed more than 100 times" do
before do
@rate_limit = Factory.create(:rate_limit, count: 101)
end
it "will be not available" do
@rate_limit.exceeded?.should be_true
end
it "can be reseted after 1 hour" do
Timecop.travel(Time.now + 1.hours + 1.minutes)
@rate_limit.exceeded?.should be_false
end
end
end
(c)2012 YourGolf Online Inc. All Rights Reserved.
21. Factory Girl
• Factory Girl is a fixtures replacement
with a straightforward definition syntax.
I m tired of fixture files.
Help me, please!
Factory Girl can help him.
(c)2012 YourGolf Online Inc. All Rights Reserved.
22. Factory Definition
FactoryGirl.define do
factory :user do
sequence(:email) {|n| "email#{n}@factory.com" }
factory :admin { admin true }
end generates unique email
factory :post do
title "My Post"
association :user
end
end
Client Code
describe User do
it "can love each other" do no need to care for the
jack = FactoryGirl.create(:user) uniqueness
rose = FactoryGirl.create(:user)
jack.girl_friend = rose
jack.loves?(rose).should be_true
end
end
23. Factory Definition
FactoryGirl.define do
factory :user do
sequence(:email) {|n| "email#{n}@factory.com" }
factory :admin { admin true }
end
factory :post do
title "My Post"
association
association :user
end
end
Client Code
describe Post do can define the association easily
it "belongs to user" do
post = FactoryGirl.create(:post)
post.user.should be
end
end
24. Capybara, Capybara-
webkit
• It helps us creating acceptance test code.
• It simulates how a real user would interact with your app.
describe "the signup process", type: :request do
before :each do
FactoryGirl.create(email: 'user@example.com', password: 'secret')
end
it "signs me in" do
within("#session") do
fill_in 'Login', with: 'user@example.com'
fill_in 'Password', with: 'secret'
end
click_link 'Sign in'
end
end
(c)2012 YourGolf Online Inc. All Rights Reserved.
25. VCR
• It records your test suite's HTTP
interactions and replay them during
future test runs for fast, deterministic,
accurate tests.
describe "VCR example group metadata", :vcr do
it 'records an http request' do
make_http_request.should == 'Hello'
end
end
(c)2012 YourGolf Online Inc. All Rights Reserved.
26. Cam on nhieu!
(c)2012 YourGolf Online Inc. All Rights Reserved.