如何测试方法,我有这个类: require 'yaml'
class Configuration
class ParseError < StandardError; end
attr_reader :config
def initialize(path)
@config = YAML.load_file(path)
rescue => e
class Post
def save
Mailer.notify!('bla')
true
end
end
如何测试当post.save被调用时,Mailer.notify方法被触发?并有正确的论点。 使用RSpec我通常做的: expect(Mailer).to receive(:notify!).with('bla')
post.save
我正在使用Rails 5 API,Pundit和一切进展顺利。我试图测试这个特定的情况,如果你不是资源所有者,你不应该能够查看该用户的信息。 因此,我得到了一些用户夹具的样本数据,莎拉和吉姆是他们中的两个。 我这里得到这个测试案例: test "user show - cannot show other user's info" do
get user_path(@sarah), hea
我正在写一个控制器测试,我想验证控制器1的call_dashboard_function。 class Controller1 < ApplicationController
before_action :init_dashb
def call_dashboard_function
@dashb.do_something!
end
def in
我想在Minitest上存根使用Mocha返回另一个存根的函数。 这是代码 @instance = stub('instance') do
stubs(:destroy).returns(true)
stubs(:id).returns(0)
end
find_by_id = stub do
stubs(:find_by_id).returns(nil) #