Ruby on rails 正在尝试引发ArgumentError rspec

Ruby on rails 正在尝试引发ArgumentError rspec,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我有一个Rspec测试没有通过,我不明白为什么。除此之外,所有其他测试均通过,该测试需要ArgumentError 测试如下所示: describe "#evaluate" do it "raises error" do expect(rpn.evaluate('%')).to raise_error(ArgumentError) end end 并且我的文件已设置,因此它将引发错误(作为else语句) 但是rspec告诉我这些 Failure/Error: e

我有一个Rspec测试没有通过,我不明白为什么。除此之外,所有其他测试均通过,该测试需要
ArgumentError

测试如下所示:

describe "#evaluate" do
    it "raises error" do
        expect(rpn.evaluate('%')).to raise_error(ArgumentError)
    end
end
并且我的文件已设置,因此它将引发错误(作为else语句)

但是rspec告诉我这些

Failure/Error: expect(rpn.evaluate('%')).to raise_error(ArgumentError)
     ArgumentError:
       ArgumentError
做:


Ie传递块以期望

将rpn.evaluate(“%”)作为参数传递与作为块传递之间的区别是

expect(rpn.evaluate('%')).to raise_error(ArgumentError)
将检查rpn.evaluate(“%”)的输出是否引发ArgumentError,而

expect { rpn.evaluate('%') }.to raise_error(ArgumentError)

将检查运行代码块rpn.evaluate(“%”)是否引发ArgumentError。

就是这样。很 完美。我得仔细研究过一个街区会有什么不同。
expect(rpn.evaluate('%')).to raise_error(ArgumentError)
expect { rpn.evaluate('%') }.to raise_error(ArgumentError)