nerd_quiz 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Portions copyright (c) 2010 Andre Arko
2
+ Portions copyright (c) 2009 Engine Yard
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -0,0 +1,3 @@
1
+ # Nerd Quiz
2
+ ## Test your nerd skills by answering NerdPursuit questions!
3
+ A ruby gem which implements a command line interface to NerdPursuit questions
data/STORIES.md ADDED
@@ -0,0 +1,8 @@
1
+ * Nerd quizer starts a quiz
2
+ * Nerd quiz asks questions
3
+ * Nerd quizer answers questions
4
+ * Nerd quiz saves the answers
5
+ * Nerd quiz ends a quiz after 10 questions
6
+ * Nerd quiz displays a final score
7
+ * Nerd quizer starts another quiz
8
+ * Nerd quizer exits
data/bin/nquiz ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV[0] == 'dev'
3
+ require_relative '../lib/nerd_quiz.rb'
4
+ else
5
+ require 'nerd_quiz'
6
+ end
7
+ NerdQuiz::Quiz.new(STDIN, STDOUT, NerdQuiz::Scorecard.new).run
@@ -0,0 +1,11 @@
1
+ Feature: Nerd quiz asks questions
2
+
3
+ As a Nerd Quiz
4
+ I want to ask questions
5
+ So that I can accept answers
6
+
7
+ Scenario: ask question
8
+ Given I am conducting a quiz
9
+ When I ask the question "What is the acronym JSON an abbreviation for?"
10
+ And A quizer answers "JavaScript Object Notation"
11
+ Then I should mark the answer as "JavaScript Object Notation"
@@ -0,0 +1,23 @@
1
+ Feature: Nerd quiz ends a quiz after 10 questions
2
+
3
+ As a Nerd Quiz
4
+ I want to end the quiz after 10 questions
5
+ So that I may tally the final score
6
+ And either exit or start a new quiz
7
+
8
+ Scenario: 10th question answered
9
+ Given I receive an answered question
10
+ And the question is the 10th
11
+ When I score the question
12
+ Then I complete the quiz
13
+ And I ask the quizer, "Would you like to take another quiz?"
14
+
15
+ Scenario: 10 questions answered correctly
16
+ Given I receive 10 correct answers
17
+ When I complete the quiz
18
+ Then I display "100% correct"
19
+
20
+ Scenario: 8 questions answered correctly
21
+ Given I receive 8 correct answers
22
+ When I complete the quiz
23
+ Then I display "80% correct"
@@ -0,0 +1,15 @@
1
+ Feature: Nerd quizer answers questions
2
+
3
+ As a Nerd Quizer
4
+ I want to answer questions
5
+ So that I can increase my final score
6
+
7
+ Scenario: answer question correctly
8
+ Given I am asked the question "What is the acronym JSON an abbreviation for?"
9
+ When I answer "JavaScript Object Notation"
10
+ Then I should see my score increase by 1
11
+
12
+ Scenario: answer question incorrectly
13
+ Given I am asked the question "What is the acronym HTTP an abbreviation for?"
14
+ When I answer "High Tea Today Please"
15
+ Then I do not see my score change
@@ -0,0 +1,11 @@
1
+ Feature: Nerd quizer starts a quiz
2
+
3
+ As a nerd quizer
4
+ I want to start a quiz
5
+ So that I can test my nerd cred
6
+
7
+ Scenario: start quiz
8
+ Given I am not yet taking a quiz
9
+ When I start a new quiz
10
+ Then I should see "Welcome to Nerd Quiz"
11
+ And I should see "Question 1:"
@@ -0,0 +1,75 @@
1
+ Given /^I am not yet taking a quiz$/ do
2
+ end
3
+
4
+ When /^I start a new quiz$/ do
5
+ NerdQuiz::Quiz.new(output).start
6
+ end
7
+
8
+ Then /^I should see "([^"]*)"$/ do |message|
9
+ output.messages.should include message
10
+ end
11
+
12
+
13
+ Given /^I am conducting a quiz$/ do
14
+ pending # express the regexp above with the code you wish you had
15
+ end
16
+
17
+ When /^I ask the question "([^"]*)"$/ do |arg1|
18
+ pending # express the regexp above with the code you wish you had
19
+ end
20
+
21
+ When /^A quizer answers "([^"]*)"$/ do |arg1|
22
+ pending # express the regexp above with the code you wish you had
23
+ end
24
+
25
+ Then /^I should mark the answer as "([^"]*)"$/ do |arg1|
26
+ pending # express the regexp above with the code you wish you had
27
+ end
28
+
29
+ Given /^I receive an answered question$/ do
30
+ pending # express the regexp above with the code you wish you had
31
+ end
32
+
33
+ Given /^the question is the (\d+)th$/ do |arg1|
34
+ pending # express the regexp above with the code you wish you had
35
+ end
36
+
37
+ When /^I score the question$/ do
38
+ pending # express the regexp above with the code you wish you had
39
+ end
40
+
41
+ Then /^I complete the quiz$/ do
42
+ pending # express the regexp above with the code you wish you had
43
+ end
44
+
45
+ Then /^I ask the quizer, "([^"]*)"$/ do |arg1|
46
+ pending # express the regexp above with the code you wish you had
47
+ end
48
+
49
+ Given /^I receive (\d+) correct answers$/ do |arg1|
50
+ pending # express the regexp above with the code you wish you had
51
+ end
52
+
53
+ When /^I complete the quiz$/ do
54
+ pending # express the regexp above with the code you wish you had
55
+ end
56
+
57
+ Then /^I display "([^"]*)"$/ do |arg1|
58
+ pending # express the regexp above with the code you wish you had
59
+ end
60
+
61
+ Given /^I am asked the question "([^"]*)"$/ do |arg1|
62
+ pending # express the regexp above with the code you wish you had
63
+ end
64
+
65
+ When /^I answer "([^"]*)"$/ do |arg1|
66
+ pending # express the regexp above with the code you wish you had
67
+ end
68
+
69
+ Then /^I should see my score increase by (\d+)$/ do |arg1|
70
+ pending # express the regexp above with the code you wish you had
71
+ end
72
+
73
+ Then /^I do not see my score change$/ do
74
+ pending # express the regexp above with the code you wish you had
75
+ end
@@ -0,0 +1 @@
1
+ require_relative '../../lib/nerd_quiz'
@@ -0,0 +1,13 @@
1
+ # Test double to fake STDOUT
2
+ class Output
3
+ def messages
4
+ @messages ||= []
5
+ end
6
+ def puts(message)
7
+ messages << message
8
+ end
9
+ end
10
+
11
+ def output
12
+ @output ||= Output.new
13
+ end
@@ -0,0 +1,28 @@
1
+ module NerdQuiz
2
+ class Question
3
+ class << self
4
+ def get
5
+ self.new
6
+ end
7
+ end
8
+
9
+ def initialize
10
+ @question = list.sample
11
+ end
12
+
13
+ def text
14
+ @question[:question]
15
+ end
16
+
17
+ def answer
18
+ @question[:answer]
19
+ end
20
+
21
+ private
22
+ def list
23
+ [
24
+ {:question => "What is the acronym JSON an abbreviation for?", :answer => "JavaScript Object Notation"}
25
+ ]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,57 @@
1
+ module NerdQuiz
2
+ class Quiz
3
+
4
+ def initialize(input, output, scorecard)
5
+ @input = input
6
+ @output = output
7
+ @scorecard = scorecard
8
+ end
9
+
10
+ def run
11
+ start
12
+ while @scorecard.incomplete?
13
+ ask
14
+ listen
15
+ end
16
+ over
17
+ end
18
+
19
+ private
20
+ def ask
21
+ @output.puts "Question #{@scorecard.next_question + 1}:"
22
+ @output.puts question
23
+ end
24
+
25
+ def listen
26
+ if reply == answer
27
+ @output.puts 'Right!'
28
+ @scorecard.right_answer!
29
+ else
30
+ @output.puts 'Wrong!'
31
+ @scorecard.wrong_answer!
32
+ end
33
+ end
34
+
35
+ def reply
36
+ @input.gets.strip
37
+ end
38
+
39
+ def start
40
+ @output.puts 'Welcome to Nerd Quiz'
41
+ end
42
+
43
+ def over
44
+ @output.puts 'Thanks For Playing!'
45
+ @output.puts @scorecard.score
46
+ end
47
+
48
+ def question
49
+ @question = NerdQuiz::Question.get
50
+ @question.text
51
+ end
52
+
53
+ def answer
54
+ @question.answer
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,45 @@
1
+ module NerdQuiz
2
+ class Scorecard
3
+ RIGHT = :right
4
+ WRONG = :wrong
5
+
6
+ attr_reader :answers
7
+
8
+ def initialize(possible=NerdQuiz::DEFAULT_NUMBER_OF_QUESTIONS)
9
+ @answers = [].fill(nil, 0, possible)
10
+ end
11
+
12
+ def next_question
13
+ @answers.index(nil)
14
+ end
15
+
16
+ def incomplete?
17
+ !next_question.nil?
18
+ end
19
+
20
+ def right_answer!
21
+ update RIGHT
22
+ end
23
+
24
+ def wrong_answer!
25
+ update WRONG
26
+ end
27
+
28
+ def score
29
+ "#{correct}/#{total}"
30
+ end
31
+
32
+ private
33
+ def update(answer)
34
+ @answers[next_question] = answer
35
+ end
36
+
37
+ def correct
38
+ @answers.select{|i| i == RIGHT}.length
39
+ end
40
+
41
+ def total
42
+ @total ||= @answers.length
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module NerdQuiz
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/nerd_quiz.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "nerd_quiz/version"
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__)) if ARGV[0] == 'dev'
2
+ require 'nerd_quiz/version'
3
+ require 'nerd_quiz/quiz'
4
+ require 'nerd_quiz/question'
5
+ require 'nerd_quiz/scorecard'
2
6
 
3
7
  module NerdQuiz
4
- # Your code goes here...
8
+ DEFAULT_NUMBER_OF_QUESTIONS = 10
5
9
  end
data/nerd_quiz.gemspec CHANGED
@@ -1,24 +1,27 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "nerd_quiz/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'nerd_quiz/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "nerd_quiz"
6
+ s.name = 'nerd_quiz'
7
7
  s.version = NerdQuiz::VERSION
8
- s.authors = ["Simeon F. Willbanks"]
9
- s.email = ["sfw@simeonfosterwillbanks.com"]
10
- s.homepage = "http://www.simeonfosterwillbanks.com"
8
+ s.authors = ['Simeon F. Willbanks']
9
+ s.email = ['sfw@simeonfosterwillbanks.com']
10
+ s.homepage = 'https://github.com/simeonwillbanks/nerd_quiz'
11
11
  s.summary = %q{A ruby gem which implements a command line interface to NerdPursuit questions}
12
12
  s.description = %q{Test your nerd skills by answering NerdPursuit questions!}
13
13
 
14
- s.rubyforge_project = "nerd_quiz"
14
+ s.rubyforge_project = 'nerd_quiz'
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
18
+ s.executables = %w(nquiz)
19
+ s.require_paths = ['lib']
20
+
21
+ s.required_ruby_version = '>= 1.9.2'
22
+ s.license = 'MIT'
20
23
 
21
24
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
25
+ s.add_development_dependency 'rspec'
26
+ s.add_development_dependency 'cucumber'
24
27
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module NerdQuiz
4
+ describe Question do
5
+ describe '.get' do
6
+ subject { Question.get }
7
+
8
+ it 'gets a new question' do
9
+ subject.should be_a Question
10
+ end
11
+
12
+ it 'which includes the question text' do
13
+ subject.should respond_to :text
14
+ subject.text.should be_a String
15
+ end
16
+
17
+ it 'and the the answer text' do
18
+ subject.should respond_to :answer
19
+ subject.answer.should be_a String
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module NerdQuiz
4
+ describe Quiz do
5
+ let(:question) { 'What is the answer to life, the universe and everything?' }
6
+ let(:answer) { '42' }
7
+ let(:output) { double('output').as_null_object }
8
+ let(:input) { double('input').as_null_object }
9
+ let(:scorecard) { NerdQuiz::Scorecard.new }
10
+ subject { Quiz.new(input, output, scorecard) }
11
+
12
+ before(:each) do
13
+ subject.stub(:answer).and_return(answer)
14
+ end
15
+
16
+ # Only public API is the run loop, so it must be run for each test
17
+ after(:each) do
18
+ subject.run
19
+ end
20
+
21
+ describe '#run' do
22
+ it 'sends a welcome message' do
23
+ output.should_receive(:puts).with('Welcome to Nerd Quiz')
24
+ end
25
+
26
+ it 'asks all the questions' do
27
+ subject.should_receive(:ask).exactly(10).times
28
+ end
29
+
30
+ it 'labels each question' do
31
+ (1..10).each do |i|
32
+ output.should_receive(:puts).with("Question #{i}:").once
33
+ end
34
+ end
35
+
36
+ context 'simulate run loop' do
37
+ before(:each) do
38
+ scorecard.stub(:incomplete?).and_return(true, true, true, true, true, true, true, true, true, true, false)
39
+ end
40
+
41
+ context 'right answer' do
42
+ before(:each) do
43
+ subject.stub(:reply).and_return(answer)
44
+ end
45
+
46
+ it 'listens for answers' do
47
+ subject.should_receive(:listen).exactly(10).times
48
+ end
49
+
50
+ it 'notifies it received the right answer' do
51
+ output.should_receive(:puts).with('Right!').exactly(10).times
52
+ end
53
+
54
+ it 'tallies the right answer' do
55
+ scorecard.should_receive(:right_answer!).exactly(10).times
56
+ end
57
+ end
58
+
59
+ context 'wrong answer' do
60
+ before(:each) do
61
+ subject.stub(:reply).and_return('Pizza, of course')
62
+ end
63
+
64
+ it 'notifies it received the wrong answer' do
65
+ output.should_receive(:puts).with('Wrong!').exactly(10).times
66
+ end
67
+
68
+ it 'tallies the wrong answer' do
69
+ scorecard.should_receive(:wrong_answer!).exactly(10).times
70
+ end
71
+ end
72
+ end
73
+
74
+ it 'proclaims the quiz over' do
75
+ output.should_receive(:puts).with('Thanks For Playing!')
76
+ end
77
+
78
+ it 'displays the final score' do
79
+ scorecard.stub(:score).and_return('10/10')
80
+ output.should_receive(:puts).with('10/10')
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ module NerdQuiz
4
+ describe Scorecard do
5
+ subject { Scorecard.new }
6
+
7
+ it 'persists the quiz answers' do
8
+ subject.should respond_to :answers
9
+ end
10
+
11
+ it 'initiates the possible answers' do
12
+ Scorecard.new(15).answers.should have(15).items
13
+ end
14
+
15
+ it 'sets a default possible answers when a default is not available' do
16
+ subject.answers.should have(10).items
17
+ end
18
+
19
+ it 'knows the score' do
20
+ subject.score.should eq('0/10')
21
+ end
22
+
23
+ it 'can tell when the card is complete' do
24
+ subject.should_receive(:next_question).and_return(nil)
25
+ subject.incomplete?.should be_false
26
+ end
27
+
28
+ it 'can tell when the card is incomplete' do
29
+ subject.should_receive(:next_question).and_return(0)
30
+ subject.incomplete?.should be_true
31
+ end
32
+
33
+ it 'when an answer is right, the score changes' do
34
+ sc = subject
35
+ expect {
36
+ sc.right_answer!
37
+ }.to change { sc.score }.to('1/10')
38
+ end
39
+
40
+ it 'when an answer is wrong, the score stays the same' do
41
+ sc = subject
42
+ sc.wrong_answer!
43
+ sc.score.should eq('0/10')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../lib/nerd_quiz'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nerd_quiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,66 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70276161146900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70276161146900
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ requirement: &70276161146440 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70276161146440
14
36
  description: Test your nerd skills by answering NerdPursuit questions!
15
37
  email:
16
38
  - sfw@simeonfosterwillbanks.com
17
- executables: []
39
+ executables:
40
+ - nquiz
18
41
  extensions: []
19
42
  extra_rdoc_files: []
20
43
  files:
21
44
  - .gitignore
45
+ - .rspec
22
46
  - Gemfile
47
+ - LICENSE
23
48
  - README.md
24
49
  - Rakefile
50
+ - STORIES.md
51
+ - bin/nquiz
52
+ - features/nerd_quiz_asks_questions.feature
53
+ - features/nerd_quiz_ends_quiz.feature
54
+ - features/nerd_quizer_answers_questions.feature
55
+ - features/nerd_quizer_starts_quiz.feature
56
+ - features/step_definitions/nerd_quiz_steps.rb
57
+ - features/support/env.rb
58
+ - features/support/output.rb
25
59
  - lib/nerd_quiz.rb
60
+ - lib/nerd_quiz/question.rb
61
+ - lib/nerd_quiz/quiz.rb
62
+ - lib/nerd_quiz/scorecard.rb
26
63
  - lib/nerd_quiz/version.rb
27
64
  - nerd_quiz.gemspec
28
- homepage: http://www.simeonfosterwillbanks.com
29
- licenses: []
65
+ - spec/nerd_quiz/question_spec.rb
66
+ - spec/nerd_quiz/quiz_spec.rb
67
+ - spec/nerd_quiz/scorecard_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: https://github.com/simeonwillbanks/nerd_quiz
70
+ licenses:
71
+ - MIT
30
72
  post_install_message:
31
73
  rdoc_options: []
32
74
  require_paths:
@@ -36,23 +78,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
78
  requirements:
37
79
  - - ! '>='
38
80
  - !ruby/object:Gem::Version
39
- version: '0'
40
- segments:
41
- - 0
42
- hash: -2443268662159488249
81
+ version: 1.9.2
43
82
  required_rubygems_version: !ruby/object:Gem::Requirement
44
83
  none: false
45
84
  requirements:
46
85
  - - ! '>='
47
86
  - !ruby/object:Gem::Version
48
87
  version: '0'
49
- segments:
50
- - 0
51
- hash: -2443268662159488249
52
88
  requirements: []
53
89
  rubyforge_project: nerd_quiz
54
90
  rubygems_version: 1.8.11
55
91
  signing_key:
56
92
  specification_version: 3
57
93
  summary: A ruby gem which implements a command line interface to NerdPursuit questions
58
- test_files: []
94
+ test_files:
95
+ - features/nerd_quiz_asks_questions.feature
96
+ - features/nerd_quiz_ends_quiz.feature
97
+ - features/nerd_quizer_answers_questions.feature
98
+ - features/nerd_quizer_starts_quiz.feature
99
+ - features/step_definitions/nerd_quiz_steps.rb
100
+ - features/support/env.rb
101
+ - features/support/output.rb
102
+ - spec/nerd_quiz/question_spec.rb
103
+ - spec/nerd_quiz/quiz_spec.rb
104
+ - spec/nerd_quiz/scorecard_spec.rb
105
+ - spec/spec_helper.rb