Guest User

Untitled

a guest
Feb 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. require 'rubygems'
  2. require 'spec'
  3.  
  4. class Person
  5. attr_accessor :name
  6. attr_accessor :shoe_size
  7.  
  8. def eat(sandwich)
  9. sandwich.cut_in_half
  10. sandwich.eaten = true
  11. end
  12.  
  13. end
  14.  
  15. class RDingus
  16.  
  17. def initialize
  18. @list = []
  19. end
  20.  
  21. def method_missing(name, *args)
  22. @list << "something"
  23. end
  24.  
  25. def calls(name)
  26. @list
  27. end
  28.  
  29. def calls?(name)
  30. true
  31. end
  32. end
  33.  
  34. describe "A person" do
  35. describe "when specifying a shoe size" do
  36.  
  37. it "should save the shoe size" do
  38. p = Person.new
  39. p.shoe_size = 4
  40. p.shoe_size.should == 4
  41. end
  42.  
  43. end
  44.  
  45. it "should be able to eat a sandwich" do
  46. sandwich = RDingus.new
  47. person = Person.new
  48. person.eat(sandwich)
  49. sandwich.calls?(:eaten=).should be_true
  50. end
  51.  
  52. end
  53.  
  54. describe "RDingus" do
  55. describe "when asserting calls" do
  56. before(:each) do
  57. @sandwich = RDingus.new
  58. end
  59. it "should return a list of methods called" do
  60. @sandwich.eaten = true
  61. @sandwich.calls(:eaten=).length.should == 1
  62. end
  63.  
  64. it "should record multiple identical calls" do
  65. 2.times do
  66. @sandwich.eaten = true
  67. end
  68. @sandwich.calls(:eaten=).length.should == 2
  69. end
  70. end
  71. end
Add Comment
Please, Sign In to add comment