我正在尝试添加写入rspec测试,该测试取决于gem用户设置为配置的内容。所以我想用某种配置运行测试。基于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
谢谢你,这也许是一个不错的选择。不过,我意识到需要运行测试多个scenarious但具有不同的配置。我正在更新我的quesiton文本以反映这一点。 –