lodestone (owner)

Revisions

gist: 73459 Download_button fork
public
Public Clone URL: git://gist.github.com/73459.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'test/unit'
 
 
class TestQ
  
  def count; 1; end
 
  def question(question, type, options={})
    '<li>What is your favorite color?</li>'
  end
  
  def questions(question_list, types=[])
    tag = ''
    types.each {|type| tag += question(question_list[self.count], type)}
    tag
  end
  
  def questions2(question_list, types=[])
    return types.inject('') {|tag, type| tag << question(question_list[self.count], type); tag}
  end
  
end
 
  class QuestionsTest < Test::Unit::TestCase
    
    def test_question
      quizmaster = TestQ.new
      question_list = { 1 => 'Ruby Ruby Ruby, Soho.' }
      types = [:number, :select]
      assert_equal quizmaster.questions(question_list, types),
                   quizmaster.questions2(question_list, types)
    end
    
  end