• Save
Curso TDD Ruby on Rails #05: Shoulda
Upcoming SlideShare
Loading in...5
×
 

Curso TDD Ruby on Rails #05: Shoulda

on

  • 1,615 views

Lección 05 del curso de TDD en Ruby on Rails:

Lección 05 del curso de TDD en Ruby on Rails:
Shoulda

Statistics

Views

Total Views
1,615
Views on SlideShare
1,602
Embed Views
13

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 13

http://www.slideshare.net 13

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

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

    Curso TDD Ruby on Rails #05: Shoulda Curso TDD Ruby on Rails #05: Shoulda Presentation Transcript

    • CURSO DE TESTING OSL 12 – 16 DE ABRIL 2010 Shoulda Alberto Perdomo Web: http://albertoperdomo.net Email: alberto.perdomo@aentos.es Twitter: @albertoperdomo http://www.aentos.com
    • TEST::UNIT → los tests no tienen mucha expresividad → las posibilidades son limitadas → acabamos probando las mismas cosas una y otra vez
    • SHOULDA → librería que “amplía” Test::Unit → helpers para contexto y expresividad → macros → helpers
    • SHOULDA: CONTEXTO Y EXPRESIVIDAD class UserTest < Test::Unit::TestCase context "A User instance" do setup do @user = User.find(:first) end should "return its full name" do assert_equal 'John Doe', @user.full_name end context "with a profile" do setup do @user.profile = Profile.find(:first) end should "return true when sent #has_profile?" do assert @user.has_profile? end end end end Produce los siguientes tests unitarios: "test: A User instance should return its full name." "test: A User instance with a profle should return true when sent #has_profle?."
    • SHOULDA: MACROS PARA ACTIVERECORD class PostTest < Test::Unit::TestCase fixtures :all should_belong_to :user should_have_many :tags, :through => :taggings should_validate_uniqueness_of :title should_validate_presence_of :body, :message => /wtf/ should_validate_presence_of :title should_validate_numericality_of :user_id end class UserTest < Test::Unit::TestCase should_have_many :posts should_not_allow_values_for :email, "blah", "b lah" should_allow_values_for :email, "a@b.com", "asdf@asdf.com" should_ensure_length_in_range :email, 1..100 should_ensure_value_in_range :age, 1..100 should_not_allow_mass_assignment_of :password end
    • MACROS PARA ACTIVERECORD test "a transfer without a from_account should not be valid" do transfer = Transfer.new(:from_account => nil, :to_account => @account_b, :amount => 100) assert !transfer.valid? end should_validate_presence_of :from_account
    • SHOULDA: MACROS PARA CONTROLADORES class PostsControllerTest < ActionController::TestCase context "on GET to :show for first record" do setup do get :show, :id => 1 end should_assign_to :user should_respond_with :success should_render_template :show should_not_set_the_flash should "do something else really cool" do assert_equal 1, assigns(:user).id end end end
    • SHOULDA: ASSERTIONS assert_same_elements([:a, :b, :c], [:c, :a, :b]) assert_contains(['a', '1'], /d/) assert_contains(['a', '1'], 'a')
    • ¿PREGUNTAS?