Skip to content

imccoy/sock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Sock: when the spec generates the mock                                                        
                                                                                              
HERE BE DRAGONS.                                                                              
                                                                                              
This is an initial experiment. Think about it. Talk about it. But if you use it               
in anger, expect it to make you angry.                                                        
                                                                                              
HERE BE DRAGONS.                                                                              
                                                                                              
Consider the following test, for a calculator class:                                          
                                                                                              
  it "returns 6 for inputs 3 and 2" do                                                        
    calculator = Calculator.new                                                               
    calculator.push(2)                                                                        
    calculator.push(3)                                                                        
    calculator.mul.should == 6                                                                
  end                                                                                         
                                                                                              
And this one, for something that uses the calculator class:                                   
                                                                                              
  it "uses the calculator to multiply 3 and 2" do                                             
    calculator.should_receive(:push).with(2)                                                  
    calculator.should_receive(:push).with(3)                                                  
    calculator.should_receive(:mul).and_return(6)                                             
    CalculatorDriver.run(calculator)                                                          
  end                                                                                         
                                                                                              
But in the real world, eventually the calculator class will change and all its                
consumers will break in real code, but the consumer's tests will keep right on                
passing. Bad. If only the mock for the latter test could be generated by the                  
former...                                                                                     
                                                                                              
Oh look. It can.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages