• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rspec
 

Rspec

on

  • 409 views

Quick Reference of Rspec Techniques

Quick Reference of Rspec Techniques

Statistics

Views

Total Views
409
Views on SlideShare
409
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rspec Rspec Presentation Transcript

    • Rspec & Factory Girl Geeta Vinnakota 7/19/2013
    • Organization ● Specs are organized in 'describe' and 'it' blocks ● Before & after hooks ● An example is nothing but an 'it' block
    • Helper Methods ● Let – lazy evaluated, ie not evaluated until the first call. The value is cached in a 'it' block ● Let! Force invocated before each 'it' block
    • Model Specs ● Spec for each class & instance method ● Call the method & match the response with the expected value ● Use Factory data to create objects to test against
    • Controller Specs ● Simulate a http request ● Views are stubbed by default. If you are using jbuilder or similar template on the api, use 'render_views' to render the views ● Also pass in the format parameter, in the request ● Check for response code, response data etc
    • Expecations ● Every object in Rspec has 2 methods should, should_not ● They accept a matcher as an argument ( matcher can act in a positive or negative mode) ● https://www.relishapp.com/rspec/rspec- expectations/v/2-13/docs/built-in-matchers
    • Mocks(Mocha) ● Mocha is the preferred framework for mocking ● Expects, with, returns ● mock_obj = Mock(obj) ● Stubs & returns on mock objects ● Set the expectation & then make the call
    • Command Line Options ● --fail-fast to exit after the first failue ● :789 - runs the spec in that line
    • FactoryGirl ● Test it on console ● require 'factory_girl' ● require 'factory_girl_rails' ● FactoryGirl.find_definitions
    • Creating Associations Using Factories ● Model belongs to another model, it contains the id of the other model.
    • When to mock & stub ● To fill up parameters in a method call ● 3rd party calls ●