gpt4 book ai didi

ruby-on-rails - 如何使用rspec规范装饰器。

转载 作者:行者123 更新时间:2023-12-04 03:51:18 26 4
gpt4 key购买 nike

我正在尝试为我的装饰器中的各个功能编写规范。我有一些针对我的助手的规范,如下所示(这只是一个示例):

book_helper.rb

module BookHelper
def heading_title
@book.name[0..200]
end
end

book_helper_spec.rb
require 'spec_helper'

describe BookHelper do
subject { FactoryGirl.build(:book) }

it 'limits title to 200 characters' do
title = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium.'
subject.name = title
subject.save
@book = subject
expect(heading_title).to eq(title[0..200])
end
end

给定以下装饰器,如何编写该功能的规范?

book_decorator.rb
class BookDecorator < Draper::Decorator
delegate_all

def display_days
model.months_to_display * 30
end
end

最佳答案

对于您的示例,我将尝试使用类似的方法:

require 'spec_helper'

describe BookDecorator do
let(:book) { FactoryGirl.build_stubbed(:book).decorate }

it 'returns the displayed days' do
expect(book.display_days).to eq('600')
end

end

关于ruby-on-rails - 如何使用rspec规范装饰器。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26834918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com