SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
Review


                         Terminology




Thursday, August 9, 12
Mocks and Stubs
                                       http://rubydoc.info/gems/rspec-mocks/

                         •   A Method Stub returns a pre-determined value.

                         •   A Mock Object is a Test Double that supports message
                             expectations and method stubs

                         •   Why should you care?




Thursday, August 9, 12
Expectations
                         http://rubydoc.info/gems/rspec-expectations/RSpec/Expectations

                         •   should

                         •   should_not

                         •   should_receive

                         •   should_not_receive

                         •   expect




Thursday, August 9, 12
Method Stubs
                                       http://rubydoc.info/gems/rspec-mocks/

                         •   A method stub returns a pre-determined value.

                         •   rspec-mocks supports 3 forms for declaring method stubs:

                                  book.stub(:title) { "The RSpec Book" }

                                  book.stub(:title => "The RSpec Book")

                                  book.stub(:title).and_return("The RSpec Book")


Thursday, August 9, 12
Mocks
                                     http://rubydoc.info/gems/rspec-mocks/

                         •   A Mock Object is a Test Double that supports message
                             expectations and method stubs

                         •   Mock Object example...




Thursday, August 9, 12
class Zombie < ActiveRecord::Base
                           has_one :weapon
                           def decapitate
                             weapon.slice(self, :head)
                             self.status = "dead again"
                           end
                         end




Thursday, August 9, 12
describe Zombie do
                           let(:zombie) { Zombie.create }
                           context "#decapitate" do
                             it "calls weapon.slice" do
                               zombie.weapon.should_receive(:slice)
                               zombie.decapitate
                             end
                             it "sets status to dead again" do
                               zombie.weapon.stub(:slice)
                               zombie.decapitate
                               zombie.status.should == "dead again"
                             end
                          end
                         end

Thursday, August 9, 12
Exercise


                         Use resource links and write some test




Thursday, August 9, 12
Resources:
                 Book:

                         •   http://www.amazon.com/The-RSpec-Book-Behaviour-Development

               Online:
                         •   http://rubydoc.info/gems/rspec-expectations/RSpec/Expectations

                         •   http://rubydoc.info/gems/rspec-expectations/RSpec/Matchers

                         •   http://rubydoc.info/gems/rspec-mocks/



Thursday, August 9, 12

Weitere ähnliche Inhalte

Andere mochten auch

Mastering Xcode 3
Mastering Xcode 3Mastering Xcode 3
Mastering Xcode 3Libin Pan
 
named_scope more detail - WebCareer
named_scope more detail - WebCareernamed_scope more detail - WebCareer
named_scope more detail - WebCareerKyosuke MOROHASHI
 
Lehmanns Rails Erweitern
Lehmanns Rails ErweiternLehmanns Rails Erweitern
Lehmanns Rails Erweiternjan_mindmatters
 
UX Design
UX DesignUX Design
UX Designluvseat
 
Preserving the web
Preserving the webPreserving the web
Preserving the webJeremy Floyd
 
Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007jan_mindmatters
 
Ruby and Sinatra's Shotgun Wedding
Ruby and Sinatra's Shotgun WeddingRuby and Sinatra's Shotgun Wedding
Ruby and Sinatra's Shotgun WeddingJamin Guy
 
Model of the colossus @ Café com Dev
Model of the colossus @ Café com DevModel of the colossus @ Café com Dev
Model of the colossus @ Café com DevMauro George
 
tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法
tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法
tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法xibbar
 
エンジニア志望だったのにRuby社長をしてよかったと思う5つのこと
エンジニア志望だったのにRuby社長をしてよかったと思う5つのことエンジニア志望だったのにRuby社長をしてよかったと思う5つのこと
エンジニア志望だったのにRuby社長をしてよかったと思う5つのことxibbar
 
Ruby ecosystem applied to agile project
Ruby ecosystem applied to agile projectRuby ecosystem applied to agile project
Ruby ecosystem applied to agile projectKyosuke MOROHASHI
 
Some Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTSome Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTFramgia Vietnam
 

Andere mochten auch (18)

Mastering Xcode 3
Mastering Xcode 3Mastering Xcode 3
Mastering Xcode 3
 
named_scope more detail - WebCareer
named_scope more detail - WebCareernamed_scope more detail - WebCareer
named_scope more detail - WebCareer
 
MüLlermilch
MüLlermilchMüLlermilch
MüLlermilch
 
Lehmanns Rails Erweitern
Lehmanns Rails ErweiternLehmanns Rails Erweitern
Lehmanns Rails Erweitern
 
UX Design
UX DesignUX Design
UX Design
 
Preserving the web
Preserving the webPreserving the web
Preserving the web
 
String Encodings
String EncodingsString Encodings
String Encodings
 
Rails 3 hints
Rails 3 hintsRails 3 hints
Rails 3 hints
 
Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007
 
Ruby and Sinatra's Shotgun Wedding
Ruby and Sinatra's Shotgun WeddingRuby and Sinatra's Shotgun Wedding
Ruby and Sinatra's Shotgun Wedding
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Model of the colossus @ Café com Dev
Model of the colossus @ Café com DevModel of the colossus @ Café com Dev
Model of the colossus @ Café com Dev
 
tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法
tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法
tDiaryなどのレガシーウェブアプリをRuby1.9で動かす方法
 
Rails21v2
Rails21v2Rails21v2
Rails21v2
 
エンジニア志望だったのにRuby社長をしてよかったと思う5つのこと
エンジニア志望だったのにRuby社長をしてよかったと思う5つのことエンジニア志望だったのにRuby社長をしてよかったと思う5つのこと
エンジニア志望だったのにRuby社長をしてよかったと思う5つのこと
 
Ruby ecosystem applied to agile project
Ruby ecosystem applied to agile projectRuby ecosystem applied to agile project
Ruby ecosystem applied to agile project
 
Some Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTSome Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDT
 
ux design
ux designux design
ux design
 

Ähnlich wie Rspec group

Moose workshop
Moose workshopMoose workshop
Moose workshopYnon Perek
 
Enterprise javascriptsession3
Enterprise javascriptsession3Enterprise javascriptsession3
Enterprise javascriptsession3Troy Miles
 
Enterprise javascriptsession2
Enterprise javascriptsession2Enterprise javascriptsession2
Enterprise javascriptsession2Troy Miles
 
Secrets of the asset pipeline
Secrets of the asset pipelineSecrets of the asset pipeline
Secrets of the asset pipelineKen Collins
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml MappingMarc Seeger
 
How and why you should test
How and why you should testHow and why you should test
How and why you should testPuppet
 
Hands on with Ruby & MongoDB
Hands on with Ruby & MongoDBHands on with Ruby & MongoDB
Hands on with Ruby & MongoDBWynn Netherland
 
Ruby 2.0 / Rails 4.0, A selection of new features.
Ruby 2.0 / Rails 4.0, A selection of new features.Ruby 2.0 / Rails 4.0, A selection of new features.
Ruby 2.0 / Rails 4.0, A selection of new features.lrdesign
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyBlazing Cloud
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresNorman Clarke
 

Ähnlich wie Rspec group (12)

Moose workshop
Moose workshopMoose workshop
Moose workshop
 
Enterprise javascriptsession3
Enterprise javascriptsession3Enterprise javascriptsession3
Enterprise javascriptsession3
 
Enterprise javascriptsession2
Enterprise javascriptsession2Enterprise javascriptsession2
Enterprise javascriptsession2
 
Secrets of the asset pipeline
Secrets of the asset pipelineSecrets of the asset pipeline
Secrets of the asset pipeline
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml Mapping
 
How and why you should test
How and why you should testHow and why you should test
How and why you should test
 
Hands on with Ruby & MongoDB
Hands on with Ruby & MongoDBHands on with Ruby & MongoDB
Hands on with Ruby & MongoDB
 
Ruby 2.0 / Rails 4.0, A selection of new features.
Ruby 2.0 / Rails 4.0, A selection of new features.Ruby 2.0 / Rails 4.0, A selection of new features.
Ruby 2.0 / Rails 4.0, A selection of new features.
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Ruby 20th birthday
Ruby 20th birthdayRuby 20th birthday
Ruby 20th birthday
 
Immutability
ImmutabilityImmutability
Immutability
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 

Kürzlich hochgeladen

The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyEthan lee
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst SummitHolger Mueller
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Catalogue ONG NUOC PPR DE NHAT .pdf
Catalogue ONG NUOC PPR DE NHAT      .pdfCatalogue ONG NUOC PPR DE NHAT      .pdf
Catalogue ONG NUOC PPR DE NHAT .pdfOrient Homes
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth MarketingShawn Pang
 
GD Birla and his contribution in management
GD Birla and his contribution in managementGD Birla and his contribution in management
GD Birla and his contribution in managementchhavia330
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Tina Ji
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessAggregage
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxAndy Lambert
 

Kürzlich hochgeladen (20)

The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst Summit
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Catalogue ONG NUOC PPR DE NHAT .pdf
Catalogue ONG NUOC PPR DE NHAT      .pdfCatalogue ONG NUOC PPR DE NHAT      .pdf
Catalogue ONG NUOC PPR DE NHAT .pdf
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
 
GD Birla and his contribution in management
GD Birla and his contribution in managementGD Birla and his contribution in management
GD Birla and his contribution in management
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
 
Best Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting PartnershipBest Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting Partnership
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for Success
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 

Rspec group

  • 1. Review Terminology Thursday, August 9, 12
  • 2. Mocks and Stubs http://rubydoc.info/gems/rspec-mocks/ • A Method Stub returns a pre-determined value. • A Mock Object is a Test Double that supports message expectations and method stubs • Why should you care? Thursday, August 9, 12
  • 3. Expectations http://rubydoc.info/gems/rspec-expectations/RSpec/Expectations • should • should_not • should_receive • should_not_receive • expect Thursday, August 9, 12
  • 4. Method Stubs http://rubydoc.info/gems/rspec-mocks/ • A method stub returns a pre-determined value. • rspec-mocks supports 3 forms for declaring method stubs: book.stub(:title) { "The RSpec Book" } book.stub(:title => "The RSpec Book") book.stub(:title).and_return("The RSpec Book") Thursday, August 9, 12
  • 5. Mocks http://rubydoc.info/gems/rspec-mocks/ • A Mock Object is a Test Double that supports message expectations and method stubs • Mock Object example... Thursday, August 9, 12
  • 6. class Zombie < ActiveRecord::Base has_one :weapon def decapitate weapon.slice(self, :head) self.status = "dead again" end end Thursday, August 9, 12
  • 7. describe Zombie do let(:zombie) { Zombie.create } context "#decapitate" do it "calls weapon.slice" do zombie.weapon.should_receive(:slice) zombie.decapitate end it "sets status to dead again" do zombie.weapon.stub(:slice) zombie.decapitate zombie.status.should == "dead again" end end end Thursday, August 9, 12
  • 8. Exercise Use resource links and write some test Thursday, August 9, 12
  • 9. Resources: Book: • http://www.amazon.com/The-RSpec-Book-Behaviour-Development Online: • http://rubydoc.info/gems/rspec-expectations/RSpec/Expectations • http://rubydoc.info/gems/rspec-expectations/RSpec/Matchers • http://rubydoc.info/gems/rspec-mocks/ Thursday, August 9, 12