Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervbk-studiare committed Jan 16, 2017
1 parent c5b6f63 commit d7f8069
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/moodle_gift_parser/multiple_choice_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def initialize
def to_gift
prefix = correct ? MoodleGiftParser::MultipleChoiceQuestion::CORRECT_ALTERNATIVE_PREFIX : MoodleGiftParser::MultipleChoiceQuestion::WRONG_ALTERNATIVE_PREFIX
# TODO parse credit/range/credit
result = "\t#{prefix}#{content}"
result << "\t#{MoodleGiftParser::MultipleChoiceQuestion::ANSWER_COMMENT_PREFIX}#{comment}" if comment
result = "\t#{prefix}#{content}\n"
result << "\t#{MoodleGiftParser::MultipleChoiceQuestion::ANSWER_COMMENT_PREFIX}#{comment}\n" if comment
return result
end

Expand Down Expand Up @@ -165,7 +165,7 @@ def initialize(question = nil)
end

def to_gift
self.options = ''
self.options = "\n"
alternatives.each do |alt|
self.options << alt.to_gift
end
Expand Down
4 changes: 2 additions & 2 deletions lib/moodle_gift_parser/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def to_gift
output << "$CATEGORY: #{category}\n" if category
output << "::#{title}::" if title
output << "[#{markup}]" if markup
output << escape_chars(content) + "{\n"
output << options + "\n}"
output << escape_chars(content) + "{"
output << options + "}"
return output
end

Expand Down
72 changes: 66 additions & 6 deletions spec/writer_single_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,85 @@
describe 'Write MultipleChoiceQuestion' do
before(:example) do
@question = MoodleGiftParser::MultipleChoiceQuestion.new
@question.comment = 'comment'
@question.category = 'category'
@question.content = 'Content'
@question.markup = 'html'
@question.alternatives
end
@question.title = 'title'

it 'should write without comment' do
alt1 = MoodleGiftParser::MultipleChoiceQuestion::Alternative.build_alternative(true)
alt1.content = 'Resposta correta'
alt1.comment = 'Resposta está correta'

alt2 = MoodleGiftParser::MultipleChoiceQuestion::Alternative.build_alternative(false)
alt2.content = 'Resposta errada 2'

alt3 = MoodleGiftParser::MultipleChoiceQuestion::Alternative.build_alternative(false)
alt3.content = 'Resposta errada 3'

@question.alternatives = [alt1, alt2, alt3]
end

it 'should write with comment' do
it 'should write with default options' do
gift = @question.to_gift
expect(gift + "\n").to eq(<<EOF
// comment
$CATEGORY: category
::title::[html]Content{
\t=Resposta correta
\t#Resposta está correta
\t~Resposta errada 2
\t~Resposta errada 3
}
EOF
)
end

it 'should write without comment' do
@question.comment = nil
gift = @question.to_gift
expect(gift + "\n").to eq(<<EOF
$CATEGORY: category
::title::[html]Content{
\t=Resposta correta
\t#Resposta está correta
\t~Resposta errada 2
\t~Resposta errada 3
}
EOF
)
end

it 'should write with category' do

it 'should write without category' do
@question.category = nil
gift = @question.to_gift
expect(gift + "\n").to eq(<<EOF
// comment
::title::[html]Content{
\t=Resposta correta
\t#Resposta está correta
\t~Resposta errada 2
\t~Resposta errada 3
}
EOF
)
end

it 'should write without title and markup' do

@question.title = nil
@question.markup = nil
gift = @question.to_gift
expect(gift + "\n").to eq(<<EOF
// comment
$CATEGORY: category
Content{
\t=Resposta correta
\t#Resposta está correta
\t~Resposta errada 2
\t~Resposta errada 3
}
EOF
)
end
end

0 comments on commit d7f8069

Please sign in to comment.