Do your test

Download Do your test

Post on 15-Jan-2015

577 views

Category:

Technology

4 download

Embed Size (px)

DESCRIPTION

 

TRANSCRIPT

<ul><li> 1. Yura TolstikRuby/Rails developer at Altoros Developmentt witter: @yltsrc email: yltsrc@gmail.com</li></ul> <p> 2. Do your testWhy?test beforesave time or or test afterwaste time 3. Save time writing code??? We spend time writing tests, butwe save time with tests, so...Spent time == Saved time 4. Rspec best practices$ rake spec...........................................................................................................................................................................................................................................................................................................................................................Finished in 0.00116 seconds 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. Establish the contextdescribe #create docontext given valid credentials doendcontext given invalid credentials doendend 7. it only expects one thingdescribe #create doit creates a new user do User.count.should == @count + 1endit sets a flash message doflash[:notice].should beendit "redirects to the new users profile" doresponse.should redirect_to(user_path(assigns(:user)))endend 8. Prefer explicitnessdescribe #new docontext when not logged in dosubject doresponseendit redirects to the sign in page doshould redirect_to(sign_in_path)endit displays a message to sign in dosubject.body.should match(/sign in/i)endendend 9. Confirm readabilityUsersController#createcreates a new usersets a flash messageredirects to the new users profile#showfinds the given userdisplays its profile#show.jsonreturns the given user as JSON#destroydeletes the given usersets a flash messageredirects to the home page 10. Use the right matcherobject.should be7.should respond_to(:zero?).with(0).arguments7.should_not be_zeroexpect { model.save! }.toraise_error(ActiveRecord::RecordNotFound)collection.should have(4).items 11. Rspec optionsdescribe "group with tagged specs" doit "example Im working now", :focus =&gt; true do; endit "slow example", :speed =&gt; slow do; endit "ordinary example", :skip =&gt; 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 = trueconfig.formatter = :documentation # :progress, :html, :textmateend 12. Cucumber best practices 13. Organize your gardenbank_account_add.featurebank_account_delete.featureuser_signup.featureuser_signup_when_invited.featureuser_login.feature 14. Thinking declarativelyScenario: Create a slideGiven I am signed in as an adminWhen I go to the admin dashboardAnd I create a new slideScenario: Create a slideGiven I am signed as an adminWhen I go to the admin dashboardAnd I create a new slideThen I should be able to edit it 15. Cucumber helps youFeature: Search engine optimizationIn order to find companyAs a future customerI want to find company in googleScenario: Find company in googleGiven 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 =&gt; :test 16. Make your scenario DRYFeature: A user can cancel a transaction unless its claimed by the recipientBackground:Given I am logged inAnd I send "$10" to "mukmuk@example.com" from my "Bank account"Scenario: I can cancel as long as the payment is not claimedWhen I cancel my latest transactionThen I should see a cancellation confirmationScenario: I cant cancel once the payment is claimedGiven "Mukmuk" claimed the latest transactionThen I cant cancel my latest transaction 17. Scenario with variablesScenario Outline: Add invalid bank account displays inlineerrorsGiven I follow "Add Bank Account"When I fill in "" with ""And I press "Add Bank Account"And I should see the inline error "" for ""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. Cucumber options@smokeFeature: Find site in search engines@javascript @wipScenario: 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 &amp;&amp; !@slow)cucumber --tags @wip --tags ~@slowcucumber features/account_*.feature --format=progress --quiet 19. Cucumber profiles#cucumber.ymldefault:</p>