2013-06-01 22 views
1

我正在使用Benedikt Diecke的自定义rspec示例组的帖子来测试活动模型串行器,但无法将此转换为使用摩卡而不是rspec mocks。将Rspec模拟转换为Mocha以测试活动模型串行器

http://benediktdeicke.com/2013/01/custom-rspec-example-groups/

的例子包括通用的方法来模拟将被序列化的模型类,它使用RSpec的嘲弄 - 我该如何将它转换为使用摩卡?

let(:resource) do 
    double(resource_name, attributes).tap do |double| 
     double.stub(:read_attribute_for_serialization) { |name| attributes[name] } 
    end 
end 

回答

3

我看不出有什么可以在那里使用模拟。我会从资源工厂方法I.e返回一个实例。自定义示例组中没有定义让(:属性)在所有的,只是定义

let(:resource) do 
    {} 
end 

,然后你的串行规范会是什么样子

require 'spec_helper' 

describe UserSerializer do 
    let(:resource){ FactoryGirl.build(:resource_name) } 

    it { should have_key(:name) } 
    it { should have_key(:email) } 
    it { should have_key(:created_at) } 
    it { should have_key(:updated_at) } 
end