Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backward truefalse arguments in example.rb #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A quiz has a mandatory name and optional time limit in minutes.
# A quiz has a mandatory name and optional duration (time limit) in seconds.
# There's also various other obscure options not documented here.

quiz 'Example quiz', :time_limit => 45 do
quiz 'Example quiz', :duration => 2700 do

# Examples of quiz questions.
# All questions have an optional :points => n that determines the
Expand Down Expand Up @@ -35,8 +35,8 @@

# true/false questions - explanation is optional

truefalse true, 'The week has 7 days.'
truefalse false, 'The earth is flat.', :explanation => 'No, just looks that way'
truefalse 'The week has 7 days.', true
truefalse 'The earth is flat.', false, :explanation => 'No, just looks that way'

# multiple choice questions (one correct answer):
# - can provide a generic 'explanation' clause and/or override it
Expand Down
2 changes: 1 addition & 1 deletion html_template/template.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="instructions">
<ul>
<li>No books, notes, or electronic devices allowed. </li>
<li>Time limit is 30 minutes.</li>
<li>Time limit is <%= duration / 60 %> minutes.</li>
<li><%= num_questions %> multiple-choice questions, points indicated per question,
<%= total_points %> points total. Points per question are intended
to reflect approximate times they should take, at about 1 point per minute.</li>
Expand Down
3 changes: 2 additions & 1 deletion lib/html5_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def render_quiz
end

def render_with_template
# 3 local variables that can should be in scope in the template:
# local variables that can be used in the template:
title = @quiz.title
total_points = @quiz.points
num_questions = @quiz.num_questions
duration = @quiz.options[:duration]
output = ERB.new(IO.read(File.expand_path @template)).result(binding)
@output = output
end
Expand Down
6 changes: 3 additions & 3 deletions spec/html5_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def write_template(str)
return f.path
end
before :each do
@atts = {:title => 'My Quiz', :points => 20, :num_questions => 5}
@quiz = mock('quiz', @atts.merge(:questions => []))
@atts = {:title => 'My Quiz', :points => 20, :num_questions => 5, :duration => 1200}
@quiz = mock('quiz', @atts.merge(:questions => [], :options => {:duration => @atts[:duration]}))
end
%w(title total_points num_questions).each do |var|
%w(title total_points num_questions duration).each do |var|
it "should set '#{var}'" do
value = @atts[var]
Html5Renderer.new(@quiz, 't' => write_template("#{var}: <%= #{value} %>")).render_quiz.output.
Expand Down
2 changes: 1 addition & 1 deletion spec/quiz_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Quiz.new('quiz',:questions => Array.new(3) { mock 'question', :points => 7 }).points.should == 21
end
describe 'should include required XML elements when XML renderer used' do
subject { Quiz.new('Foo', :maximum_submissions => 2, :start => '2011-01-01 00:00', :time_limit => 60).render_with(:xml) }
subject { Quiz.new('Foo', :maximum_submissions => 2, :start => '2011-01-01 00:00', :duration => 3600).render_with(:xml) }
{'title' => 'Foo',
'maximum_submissions' => '2',
'type' => 'quiz' }.each_pair do |element, value|
Expand Down