Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduce RSpec's Matchers

3,466 views

Published on

Published in: Technology
  • Be the first to comment

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

×