我有这样的代码:
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
但它无法正常工作。如何解决?
答案 0 :(得分:-1)
将您的OR
更改为以下内容:
subject