VCR Lightning Talk

4,205 views
4,183 views

Published on

Dan Pickett presents a quick overview of VCR to Boston.rb

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,205
On SlideShare
0
From Embeds
0
Number of Embeds
3,057
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • VCR Lightning Talk

    1. 1. VCR
    2. 2. Hi!www.enlightsolutions.comon the InterWeb dpickett on the Twitterz
    3. 3. TDD and You• Test First• Test Often• Test Everything...including integrations with third party web services
    4. 4. Tests Should BeDeterministicDo they run the same way?With the same results?Regardless of your system state?
    5. 5. Would your build be clean...Without a network connection?When a third party changes their api?When a third party is unavailable?
    6. 6. Fakeweb and Webmock• “Mocks” web requests with fixtures• Allows you to run integration tests without a network connection• You manually set an expectation of what request will be issued and what response will result
    7. 7. FakeWeb.register_uri(:get, "http://example.com/test1", :body => "Hello World!")Net::HTTP.get(URI.parse("http://example.com/test1"))=> "Hello World!"Net::HTTP.get(URI.parse("http://example.com/test2"))=> FakeWeb is bypassed and the response from a real request isreturned
    8. 8. Why Does this Suck?• You have to manually curl the request to get a response to fuel your tests• It’s a manual process that’s prone to user error and efficiency problems
    9. 9. VCR• Records requests and responses for you• Uses ERB so you can dynamically populate dynamic and secure stuff• Supports both WebMock and Fakeweb
    10. 10. require rubygemsrequire test/unitrequire vcrVCR.config do |c| c.cassette_library_dir = fixtures/vcr_cassettes c.stub_with :webmock # or :fakewebendclass VCRTest < Test::Unit::TestCase def test_example_dot_com VCR.use_cassette(synopsis, :record => :new_episodes) do response = Net::HTTP.get_response(URI.parse(http://example.com/)) assert_match /You have reached this web page by typing.*example.com/, response.body end endend
    11. 11. ...Even Works With Cucumberfeatures/support/vcr.rbrequire vcrVCR.config do |c| c.cassette_library_dir = features/cassettes c.stub_with :webmock c.default_cassette_options = { :record => :none }endVCR.cucumber_tags do |t| t.tags @stub_facebook, :record => :new_episodesend
    12. 12. Don’t Commit Secure Credentials Hide you keys, hide your tokens
    13. 13. Use VCR’s New FilteringVCR.config do |c| c.filter_sensitive_data(<MERCHANT_ID>) do braintree_config.merchant_id end c.filter_sensitive_data(<PUBLIC_KEY>) do braintree_config.public_key endend
    14. 14. Drawbacks• Deterministic when you want nondeterminism• No baked in way to obscure credentials• Does not work with libcurl based HTTP requests
    15. 15. A worthwhile addition to your testing library Now with Typhoeus and Faraday supportMade with tiger blood
    16. 16. A worthwhile additionToken Charlie Sheen Reference to your testing library Your Welcome. Now with Typhoeus and Faraday support Made with tiger blood
    17. 17. Thanks!• I’ll post slides @ www.enlightsolutions.com• Chat me up on Twitter: @dpickett• Chat me up on IRC: dpickett in #boston.rb

    ×