by whatsound



RSpec
LiveCoding#7
            ( )
      ...
(@Sixeight)
[       ]
    You.should join(:us)
Case -> Matchers
test-unit 2.0.5
Test::Unit + Shoulda
Test::Unit + Coulda
RSpec
CASE:
1.should == 1
1.should == 1
1.should == 1
1.should == 1
1.should == 1
Matchers
he.should play(:piano)
he.should play(:piano)
CASE:
[].empty? == true
[].empty?.should == true
×
[].empty?.should == true
Predicates
be_xxx
[].should be_empty
[].should be_empty

    [].empty?
be_true
 be_false
   be_nil
be_activate
be_a_xxx
be_an_xxx
be_a_kind_of(*args)
be_an_instance_of(*args)
CASE:
1.05   1.15
be_close(expected, delta)
value.should be_close(1.1, 0.5)
CASE:
change(receiver, message, &block)
#
lambda {
 Date(2009, 7, 6).next
}.should change(hitagi, :age).by(1)
#
lambda {
 Date(2009, 7, 6).next
}.should change(hitagi, :age).by(1)
#
lambda {
 Date(2009, 7, 6).next
}.should change(hitagi, :age).by(1)
CASE:
5 == 5
5.should eql(5)
obj == other
obj.should equal(other)
/hane/ =~ ‘hanekawa’
‘hanekawa’.should match(/hane/)
CASE:
exist
File.should exist(‘staple’)
CASE:
i.should respond_to(:say)
i.should respond_to(:say).
  with(‘love you’)
CASE:
have(n)
hitagi.should have(140).stationeries
hitagi.should have(140).stationeries
have == have_exactly
n
nadeko.should have_at_least(2).snakes
n
have_at_most
CASE:
[1, 2, 3].should include(2)
[1, 2, 3].should include(1, 3)
CASE:
lambda {
 danger_method
}.should raise_error
Throw
lambda {
 pitcher_method
}.should throw_symbol
CASE:
true
satisfy
oshino.satisfy do |o|
 o.battles_against(:me)
 o.battles_against(:you)
 o.alive?
end
RSpec
Matcher
RDoc
http://rspec.rubyforge.org/rspec/1.2.9/
you.should have_at_least(1).question
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Introduce RSpec's Matchers
Upcoming SlideShare
Loading in …5
×

Introduce RSpec's Matchers

3,195
-1

Published on

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

No Downloads
Views
Total Views
3,195
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
25
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • Introduce RSpec's Matchers

    1. 1. by whatsound RSpec
    2. 2. LiveCoding#7 ( ) ...
    3. 3. (@Sixeight)
    4. 4. [ ] You.should join(:us)
    5. 5. Case -> Matchers
    6. 6. test-unit 2.0.5
    7. 7. Test::Unit + Shoulda Test::Unit + Coulda
    8. 8. RSpec
    9. 9. CASE:
    10. 10. 1.should == 1
    11. 11. 1.should == 1
    12. 12. 1.should == 1
    13. 13. 1.should == 1
    14. 14. 1.should == 1
    15. 15. Matchers
    16. 16. he.should play(:piano)
    17. 17. he.should play(:piano)
    18. 18. CASE:
    19. 19. [].empty? == true
    20. 20. [].empty?.should == true
    21. 21. × [].empty?.should == true
    22. 22. Predicates
    23. 23. be_xxx
    24. 24. [].should be_empty
    25. 25. [].should be_empty [].empty?
    26. 26. be_true be_false be_nil be_activate
    27. 27. be_a_xxx be_an_xxx
    28. 28. be_a_kind_of(*args) be_an_instance_of(*args)
    29. 29. CASE:
    30. 30. 1.05 1.15
    31. 31. be_close(expected, delta)
    32. 32. value.should be_close(1.1, 0.5)
    33. 33. CASE:
    34. 34. change(receiver, message, &block)
    35. 35. # lambda { Date(2009, 7, 6).next }.should change(hitagi, :age).by(1)
    36. 36. # lambda { Date(2009, 7, 6).next }.should change(hitagi, :age).by(1)
    37. 37. # lambda { Date(2009, 7, 6).next }.should change(hitagi, :age).by(1)
    38. 38. CASE:
    39. 39. 5 == 5
    40. 40. 5.should eql(5)
    41. 41. obj == other
    42. 42. obj.should equal(other)
    43. 43. /hane/ =~ ‘hanekawa’
    44. 44. ‘hanekawa’.should match(/hane/)
    45. 45. CASE:
    46. 46. exist
    47. 47. File.should exist(‘staple’)
    48. 48. CASE:
    49. 49. i.should respond_to(:say)
    50. 50. i.should respond_to(:say). with(‘love you’)
    51. 51. CASE:
    52. 52. have(n)
    53. 53. hitagi.should have(140).stationeries
    54. 54. hitagi.should have(140).stationeries
    55. 55. have == have_exactly
    56. 56. n
    57. 57. nadeko.should have_at_least(2).snakes
    58. 58. n
    59. 59. have_at_most
    60. 60. CASE:
    61. 61. [1, 2, 3].should include(2)
    62. 62. [1, 2, 3].should include(1, 3)
    63. 63. CASE:
    64. 64. lambda { danger_method }.should raise_error
    65. 65. Throw
    66. 66. lambda { pitcher_method }.should throw_symbol
    67. 67. CASE:
    68. 68. true
    69. 69. satisfy
    70. 70. oshino.satisfy do |o| o.battles_against(:me) o.battles_against(:you) o.alive? end
    71. 71. RSpec Matcher
    72. 72. RDoc http://rspec.rubyforge.org/rspec/1.2.9/
    73. 73. you.should have_at_least(1).question
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×