Sha256: f8e0c6390b19ea2dc5f63bc6826faa6107c13cc63f7941fdbb9fd9d4e4eb5a14
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
require 'rails_helper' module Quizzes RSpec.describe QuestionFactory, type: :model do before(:each) do create_questions_in_sequence(20) end it "returns the informed number of questions" do expect( QuestionFactory.new({ levels: Level.all_and_nil, number_of_questions: 2 }).generate.size ).to eq(2) end it "returns existing number of questions when what is informed exceeds the total" do expect( QuestionFactory.new({ levels: Level.all_and_nil, number_of_questions: 44 }).generate.size ).to eq(20) end it "considers the level" do level = create(:level) question = create(:question, text: "Question of level #{level.name}", level: level) expect( QuestionFactory.new({ levels: [level], number_of_questions: 1 }).generate.first.text ).to eq("Question of level #{level.name}") end it "returns unique questions" do ids = QuestionFactory.new({ levels: Level.all_and_nil, number_of_questions: 10 }).generate.map(&:id) expect(ids.size).to eq(ids.uniq.size) end it "avoids questions already used" do level = create(:level) used_question = create(:question, text: "Question of level #{level.name}", level: level) questions = QuestionFactory.new({ levels: [level], used_questions: [used_question], number_of_questions: 15 }).generate questions.each do |question| expect(question).not_to eq(used_question) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
quizzes-0.1.1 | spec/models/quizzes/question_factory_spec.rb |
quizzes-0.1.0 | spec/models/quizzes/question_factory_spec.rb |