brianjlandau (owner)

Revisions

gist: 216492 Download_button fork
public
Public Clone URL: git://gist.github.com/216492.git
Embed All Files: show embed
mocking_kernel_methods.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'test/unit'
require 'mocha'
require 'shoulda'
 
class Snowflake
  def execute_something
    system "/bin/ls -A1 ~"
  end
end
 
 
class SomeTest < Test::Unit::TestCase
  context 'Testing a feature' do
    setup do
      @snow = Snowflake.new
    end
    
    should 'execute system call' do
      @snow.class_eval do
        def system(*args); end
      end
      @snow.expects(:system).with("/bin/ls -A1 ~").returns(true)
      
      @snow.execute_something
    end
  end
end