【发布时间】:2015-05-01 08:39:29
【问题描述】:
我有这样的代码:
class FooBar
include HTTParty
def self.token
fail Project::MissingToken unless Project::Config.key?("project_token")
Project::Config.fetch("project_token")
end
base_uri "https://website.com/api"
default_params token: token
end
现在我需要测试Project::Config 不包含密钥并引发异常的情况。我正在考虑类似的事情:
context "token is not given" do
subject { Project::FooBar }
it "should raise an error" do
expect(Project::Config).to receive(:key?).with("project_token").and_return(false)
expect { subject }.to raise_error(Project::MissingToken)
end
end
但它不能正常工作。如何解决?
【问题讨论】: