Do your test

755 views

Published on

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
755
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Do your test

  1. 1. Yura TolstikRuby/Rails developer at Altoros Development t witter: @yltsrc email: yltsrc@gmail.com
  2. 2. Do your test Why?test before save time or or test after waste time
  3. 3. Save time writing code??? We spend time writing tests, but we save time with tests, so... Spent time == Saved time
  4. 4. Rspec best practices$ rake spec...........................................................................................................................................................................................................................................................................................................................................................Finished in 0.00116 seconds
  5. 5. 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
  6. 6. Establish the contextdescribe #create do  context given valid credentials do  end   context given invalid credentials do  endend
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. Cucumber best practices
  13. 13. Organize your gardenbank_account_add.featurebank_account_delete.featureuser_signup.featureuser_signup_when_invited.featureuser_login.feature
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. 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 | 
  18. 18. 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
  19. 19. 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
  20. 20. 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/

×