에서 메소드에 도달하지 못합니다. ruby / rspec을 처음 접하고 메소드가 예외를 발생시키는 지 테스트하려고합니다. 나는 이것에 대해 완전히 잘못 될 수 있습니다.RSpec은 클래스
#require 'rspec'
describe "TestClass" do
it "should raise exception when my method is called" do
test = Test.new
test.should_receive(:my_method).and_raise
end
end
class Test
def my_method
raise
end
end
rspec test.rb
F
Failures:
1) TestClass should raise exception when my method is called
Failure/Error: test.should_receive(:my_method).and_raise
(#<Test:0x007fc61c82f7c8>).my_method(any args)
expected: 1 time
received: 0 times
# ./test.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.00061 seconds
1 example, 1 failure
Failed examples:
rspec ./test.rb:4 # TestClass should raise exception when my method is called
왜 메시지가 0 번 수신 되었습니까?
감사! 나는 다른 곳에 참조 된 것을 보았다. should_receive를 완전히 오용했다. – sclarson
@sparks yup! : D 나는 rspec으로 오랜 시간 동안 어려움을 겪었고, 존재하는 모든 다양한 도우미에 치트 시트를 사용하고자합니다. https://gist.github.com/steveclarke/2353100 –