【发布时间】:2015-05-07 10:50:13
【问题描述】:
我正在尝试添加编写一个依赖于 gem 用户设置为配置的 rspec 测试。所以我想用某种配置运行测试。
这是配置:
Tasuku.configure do |config|
config.update_answers = false
end
这是当然只有在上面的配置设置为 false 时才有意义的测试:
describe '#can_only_answer_each_question_once' do
let!(:question) { create :question_with_options }
let!(:answer) { create :question_answer, author: user, options: [question.options.first] }
let!(:duplicate_answer) { build :question_answer, author: user, options: [question.options.first] }
it 'prohibits an author from answering the same question more than once' do
expect(duplicate_answer).not_to be_valid
end
it 'should have errors' do
expect(duplicate_answer.errors_on(:base)).to eq [I18n.t('tasuku.taskables.questions.answers.already_answered')]
end
end
【问题讨论】:
标签: ruby-on-rails ruby rspec config