Advertisement
Guest User

Rspec Testing

a guest
Jun 30th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.71 KB | None | 0 0
  1. require 'spec_helper'
  2. require_relative '../my_example'
  3.  
  4. describe MyExample do
  5.  
  6. let(:message_var) {"A message"}
  7.  
  8.   context 'when creating' do
  9.  
  10.     it 'should call message method with message_var' do
  11.       expect_any_instance_of(MyExample).to receive(:message).with(message_var)
  12.       MyExample.new(message_var)
  13.     end
  14.  
  15.     it 'should call message method with message_var and return message_var in reverse' do
  16.       expect_any_instance_of(MyExample).to receive(:message).with(message_var).and_return("this should fail")
  17.       MyExample.new(message_var)
  18.     end
  19.   end
  20. end
  21.  
  22. ../my_example
  23.  
  24. class MyExample
  25.  
  26.   def initialize(m)
  27.     message(m)
  28.   end
  29.  
  30.   def message(m)
  31.     return m.reverse
  32.   end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement