initial commit
This commit is contained in:
commit
9488b12033
|
@ -0,0 +1,4 @@
|
|||
# A sample Gemfile
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rspec"
|
|
@ -0,0 +1,18 @@
|
|||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.1.3)
|
||||
rspec (2.8.0)
|
||||
rspec-core (~> 2.8.0)
|
||||
rspec-expectations (~> 2.8.0)
|
||||
rspec-mocks (~> 2.8.0)
|
||||
rspec-core (2.8.0)
|
||||
rspec-expectations (2.8.0)
|
||||
diff-lcs (~> 1.1.2)
|
||||
rspec-mocks (2.8.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
rspec
|
|
@ -0,0 +1,5 @@
|
|||
Demonstrates use of stubbing methods using RSpec Mocks (and RSpec Expectations).
|
||||
|
||||
You can learn about RSpec at https://www.relishapp.com/rspec
|
||||
|
||||
To run the tests: "rspec spec/"
|
|
@ -0,0 +1,17 @@
|
|||
class MyClass
|
||||
|
||||
attr_accessor :name
|
||||
|
||||
def initialize(name="default")
|
||||
@name = name
|
||||
end
|
||||
|
||||
def self.a_class_method
|
||||
"default class impl"
|
||||
end
|
||||
|
||||
def an_instance_method
|
||||
"default instance impl for #{@name}"
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,40 @@
|
|||
require File.dirname(__FILE__) + '/../lib/simple.rb'
|
||||
|
||||
describe "basic tests" do
|
||||
it "can create instance" do
|
||||
inst = MyClass.new
|
||||
inst.should_not be_nil
|
||||
end
|
||||
it "defaults name" do
|
||||
inst = MyClass.new
|
||||
inst.name.should == "default"
|
||||
end
|
||||
it "has a class method" do
|
||||
MyClass.a_class_method.should match("default class impl")
|
||||
end
|
||||
it "has an instance method" do
|
||||
inst = MyClass.new
|
||||
inst.an_instance_method.should match("default instance impl for default")
|
||||
end
|
||||
it "can set name" do
|
||||
inst = MyClass.new("hello")
|
||||
inst.name.should == "hello"
|
||||
end
|
||||
end
|
||||
|
||||
describe "stub methods" do
|
||||
it "can stub class methods" do
|
||||
MyClass.stub(:a_class_method).and_return("a stubbed method")
|
||||
MyClass.a_class_method.should match("a stubbed method")
|
||||
end
|
||||
it "invoking stub on class does not affect instance methods" do
|
||||
MyClass.stub(:an_instance_method).and_return("a stubbed method")
|
||||
inst = MyClass.new
|
||||
inst.an_instance_method.should match("default instance impl for default")
|
||||
end
|
||||
it "can stub instance methods" do
|
||||
MyClass.any_instance.stub(:an_instance_method).and_return("a stubbed instance method")
|
||||
inst = MyClass.new
|
||||
inst.an_instance_method.should match("a stubbed instance method")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue