Created
September 13, 2013 09:32
rspec_stub_bug????
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
class A | |
def load_setting | |
YAML.load_file("./hoge.yaml") # hoge.yaml => setting: 1 | |
end | |
end | |
class B | |
CONST = A.new.load_setting | |
CONST2 = YAML.load_file("./hoge.yaml") | |
def self.load_setting_singleton | |
YAML.load_file("./hoge.yaml") | |
end | |
def load_setting | |
YAML.load_file("./hoge.yaml") | |
end | |
end | |
describe A do | |
# success | |
it "should 1" do | |
expect = {"setting" => 1} | |
A.new.load_setting.should eq expect | |
end | |
end | |
describe B do | |
before do | |
setting_stub = {"setting" => 2} | |
YAML.stub(:load_file).and_return setting_stub | |
end | |
# success | |
context "load_setting_singleton" do | |
it "shoud be 2" do | |
expected = {"setting" => 2} | |
B.load_setting_singleton.should eq expected | |
end | |
end | |
# success | |
context "load_setting" do | |
it "should be 2" do | |
expected = {"setting" => 2} | |
B.new.load_setting.should eq expected | |
end | |
end | |
# fail | |
# not applied stub | |
context "CONST" do | |
it "shoud be 2" do | |
expected = {"setting" => 2} | |
B::CONST.should eq expected | |
end | |
end | |
# fail | |
# not applied stub | |
context "CONST2" do | |
it "shoud be 2" do | |
expected = {"setting" => 2} | |
B::CONST2.should eq expected | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
stub_const