• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Do your test
 

Do your test

on

  • 731 views

 

Statistics

Views

Total Views
731
Views on SlideShare
731
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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

    Do your test Do your test Presentation Transcript

    • Yura TolstikRuby/Rails developer at Altoros Development t witter: @yltsrc email: yltsrc@gmail.com
    • Do your test Why?test before save time or or test after waste time
    • Save time writing code??? We spend time writing tests, but we save time with tests, so... Spent time == Saved time
    • Rspec best practices$ rake spec...........................................................................................................................................................................................................................................................................................................................................................Finished in 0.00116 seconds
    • Describe what you are doing describe User do   describe .authenticate do   end   describe .admins do   end   describe #admin? do   end   describe #name do   end end
    • Establish the contextdescribe #create do  context given valid credentials do  end   context given invalid credentials do  endend
    • it only expects one thingdescribe #create do it creates a new user do   User.count.should == @count + 1  end   it sets a flash message do    flash[:notice].should be  end   it "redirects to the new users profile" do    response.should redirect_to(user_path(assigns(:user)))  endend
    • Prefer explicitnessdescribe #new do context when not logged in do    subject do      response    end    it redirects to the sign in page do      should redirect_to(sign_in_path)    end    it displays a message to sign in do      subject.body.should match(/sign in/i)    end  endend
    • Confirm readabilityUsersController  #create    creates a new user    sets a flash message    redirects to the new users profile  #show    finds the given user    displays its profile  #show.json    returns the given user as JSON  #destroy    deletes the given user    sets a flash message    redirects to the home page
    • Use the right matcherobject.should be7.should respond_to(:zero?).with(0).arguments7.should_not be_zeroexpect { model.save! }.to raise_error(ActiveRecord::RecordNotFound)collection.should have(4).items
    • Rspec optionsdescribe "group with tagged specs" do it "example Im working now", :focus => true do; end it "slow example", :speed => slow do; end it "ordinary example", :skip => true do; endendrspec spec/*_spec.rb --tag @focusrspec spec/*_spec.rb --tag ~@focusrspec spec/*_spec.rb --tag @speed:slowrspec spec/*_spec.rb --format=progress --color# spec_helper.rbRSpec.configure do |config| config.color_enabled = true config.formatter = :documentation # :progress, :html, :textmateend
    • Cucumber best practices
    • Organize your gardenbank_account_add.featurebank_account_delete.featureuser_signup.featureuser_signup_when_invited.featureuser_login.feature
    • Thinking declarativelyScenario: Create a slide Given I am signed in as an admin When I go to the admin dashboard And I create a new slideScenario: Create a slide Given I am signed as an admin When I go to the admin dashboard And I create a new slide Then I should be able to edit it
    • Cucumber helps youFeature: Search engine optimization In order to find company As a future customer I want to find company in google Scenario: Find company in google Given I ask google for "company" Then I should see "http://company.url"$ cucumber...Given /^I ask google for "([^"]*)"$/ do |arg1| pendingend#Gemfilegem "cucumber-rails-training-wheels", :group => :test
    • Make your scenario DRYFeature: A user can cancel a transaction unless its claimed by the recipient   Background:    Given I am logged in    And I send "$10" to "mukmuk@example.com" from my "Bank account"   Scenario: I can cancel as long as the payment is not claimed    When I cancel my latest transaction    Then I should see a cancellation confirmation   Scenario: I cant cancel once the payment is claimed    Given "Mukmuk" claimed the latest transaction    Then I cant cancel my latest transaction
    • Scenario with variablesScenario Outline: Add invalid bank account displays inline errors  Given I follow "Add Bank Account"  When I fill in "<field>" with "<value>"  And I press "Add Bank Account"  And I should see the inline error "<error>" for "<field>"   Examples:    | field   | value         | error                    |    | Account |               | Cant be blank           |    | Account | Sixty five    | Should be 1 to 12 digits |    | Account | 1234567890123 | Should be 1 to 12 digits | 
    • Cucumber options@smokeFeature: Find site in search engines @javascript @wip Scenario: Find site in googlecucumber --name "Find site in search engines"cucumber features --tags @wip:3cucumber --tags @wip,@smoke # logical OR (@wip || @smoke)# logical AND (@wip && !@slow)cucumber --tags @wip --tags ~@slowcucumber features/account_*.feature --format=progress --quiet
    • Cucumber profiles#cucumber.yml<%std_opts = "--format pretty --quiet --strict --tags ~@wip"%>default: <%= std_opts << " --tags ~@javascript" %> featuresselenium: <%= std_opts %> featureswip: --tags @wip:3 --wip featurescucumber --profile=wiprake cucumber:wip
    • Questions http://blog.carbonfive.com/2010/10/21/rspec-best-practices/ https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/command-line/ https://github.com/rspec/rspec-expectationshttp://eggsonbread.com/2010/09/06/my-cucumber-best-practices-and-tips/