gates_of_moria 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/gates_of_moria +12 -0
- data/gates_of_moria.gemspec +24 -0
- data/lib/gates_of_moria.rb +8 -0
- data/lib/gates_of_moria/motd.txt +35 -0
- data/lib/gates_of_moria/questions.json +13 -0
- data/lib/gates_of_moria/quiz.rb +20 -0
- data/lib/gates_of_moria/repl.rb +68 -0
- data/lib/gates_of_moria/version.rb +3 -0
- data/spec/acceptance/player_starts_the_quiz.feature +24 -0
- data/spec/acceptance/steps/player_steps.rb +46 -0
- data/spec/fixtures/one_question.json +9 -0
- data/spec/gates_of_moria/quiz_spec.rb +17 -0
- data/spec/gates_of_moria/repl_spec.rb +38 -0
- data/spec/spec_helper.rb +5 -0
- metadata +122 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-r turnip/rspec
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@gates_of_moria --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Matt Gauger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# The Gates Of Moria
|
2
|
+
|
3
|
+
A simple quiz to test Ruby knowledge.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gates_of_moria'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gates_of_moria
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Run `gates_of_moria` and follow instructions.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/gates_of_moria
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gates_of_moria/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "gates_of_moria"
|
8
|
+
gem.version = GatesOfMoria::VERSION
|
9
|
+
gem.authors = ["Matt Gauger", "Jaymes Waters"]
|
10
|
+
gem.email = ["matt@bendyworks.com"]
|
11
|
+
gem.description = %q{A simple quiz to test Ruby knowledge}
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = "https://github.com/mathias/gates_of_moria"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('rspec', '~> 2.11.0')
|
21
|
+
gem.add_development_dependency('turnip')
|
22
|
+
gem.add_development_dependency('pry')
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
______________ _ _,-----------._ ___
|
2
|
+
| | (_,.- _,-'_,-----------._`-._ _)_)
|
3
|
+
| THE _ _ _ | | ,'_,-' ___________ `-._`.
|
4
|
+
| | / \|_)| \ | `' ,',' _,-'___________`-._ `.`.
|
5
|
+
| |__\_/| \|_/ | ,',' ,'_,-' . `-._`. `.`.
|
6
|
+
| | /,' ,',' >|< `.`. `.\
|
7
|
+
| OF THE _ _ | // ,',' >< ,^. >< `.`. \\
|
8
|
+
| |_)||\|/_(_ | // /,' >< / | \ >< `.\ \\
|
9
|
+
| | \|| |\_|_) | // // >< \/\^/\/ >< \\ \\
|
10
|
+
|______________| ;; ;; `---' :: ::
|
11
|
+
|| || (____ || ||
|
12
|
+
DOORS OF DURIN _||__||_ ,'----. _||__||_
|
13
|
+
(o.____.o)____ `---' ____(o.____.o)
|
14
|
+
| | /,--.) (,--.\ | |
|
15
|
+
| |(( -`___ ___` ))| |
|
16
|
+
| | \\,'', `. .' .``.// | |
|
17
|
+
| | // (___,'. .'.___) \\ | |
|
18
|
+
/| | ;;)) ____) . . (____ ((\\ | |\
|
19
|
+
\|.__ | ||/ .'.--.\/ `/,--.`. \;: | __,|;
|
20
|
+
|`-,`;.| :/ /,' `)-' `-(' `.\ \: |.;',-'|
|
21
|
+
| `.. ' / \__.' `.__/ \ ` ,.' |
|
22
|
+
| |,\ /, ,\ /,| |
|
23
|
+
| ||: : ) . ( : :|| |
|
24
|
+
/| |:; |/ . ./|\, , \| :;| |\
|
25
|
+
\|.__ |/ : ,/- <--:--> ,\. ; \| __,|;
|
26
|
+
|`-.``: `'/-. '\|/` ,-\`; ;'',-'|
|
27
|
+
| `.. ,' `' ' ` `. ,.' |
|
28
|
+
| || : : || |
|
29
|
+
| || | | || |
|
30
|
+
| || | | || |
|
31
|
+
| |' | _ | `| |
|
32
|
+
| | | '|)) | | |
|
33
|
+
;____: `._ `' _,' ;____:
|
34
|
+
{______} \___________________/ {______}
|
35
|
+
SSt |______|_______________________________|______|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"questions": [
|
3
|
+
{
|
4
|
+
"initial_prompt": "Let me know your name by assigning it to a variable called '@name'!",
|
5
|
+
"expected_response": "@name.class == String && @name.length > 0",
|
6
|
+
"help_texts": [ "Let me know your name by assigning it to a variable called '@name'!", "Variables hold information. We use the equal sign to assign information into a variable:\n@name = \"Matt\"", "bar", "baz" ]
|
7
|
+
}, {
|
8
|
+
"expected_response": "result == 'friend'",
|
9
|
+
"help_texts": ["Now send the string 'sevraq' to the translate method."],
|
10
|
+
"setup_code": "def translate(s); s.tr!('A-Za-z', 'N-ZA-Mn-za-m'); end"
|
11
|
+
}
|
12
|
+
]
|
13
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GatesOfMoria
|
2
|
+
class Quiz
|
3
|
+
attr_accessor :motd
|
4
|
+
|
5
|
+
def initialize(output_buffer, input_buffer, motd = nil)
|
6
|
+
@output_buffer = output_buffer
|
7
|
+
@input_buffer = input_buffer
|
8
|
+
@motd = motd || File.read('lib/gates_of_moria/motd.txt')
|
9
|
+
@questions = File.read('lib/gates_of_moria/questions.json')
|
10
|
+
end
|
11
|
+
|
12
|
+
def start
|
13
|
+
@output_buffer.puts @motd
|
14
|
+
@repl = GatesOfMoria::REPL.new(@output_buffer, @input_buffer, @questions)
|
15
|
+
|
16
|
+
@repl.start
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module GatesOfMoria
|
2
|
+
class REPL
|
3
|
+
def initialize(output_buffer, input_buffer, questions)
|
4
|
+
@output_buffer = output_buffer
|
5
|
+
@input_buffer = input_buffer
|
6
|
+
|
7
|
+
@questions = JSON.parse(questions)['questions']
|
8
|
+
end
|
9
|
+
|
10
|
+
def start
|
11
|
+
ask_the_questions
|
12
|
+
end
|
13
|
+
|
14
|
+
def answer_question(expected_answer, user_input)
|
15
|
+
begin
|
16
|
+
result = eval(user_input)
|
17
|
+
rescue SyntaxError, Exception
|
18
|
+
politely_say_their_ruby_is_invalid
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
@output_buffer.puts "\n=> #{result}\n"
|
22
|
+
eval(expected_answer)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def ask_the_questions
|
27
|
+
@questions.each do |question|
|
28
|
+
if prompt_with_help_texts question
|
29
|
+
display_you_are_correct
|
30
|
+
next
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
|
36
|
+
def prompt_with_help_texts question
|
37
|
+
eval(question['setup_code']) if question.has_key?('setup_code')
|
38
|
+
question['help_texts'].each do |ht|
|
39
|
+
prompt_question ht
|
40
|
+
|
41
|
+
return true if answer_question(question['expected_response'], get_user_input)
|
42
|
+
politely_say_they_are_wrong
|
43
|
+
end
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
|
47
|
+
def prompt_question prompt
|
48
|
+
@output_buffer.print "\n#{prompt}\n> "
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_user_input
|
52
|
+
input = @input_buffer.gets
|
53
|
+
(input || '').chomp
|
54
|
+
end
|
55
|
+
|
56
|
+
def politely_say_their_ruby_is_invalid
|
57
|
+
@output_buffer.puts("That doesn't look like Ruby to me.")
|
58
|
+
end
|
59
|
+
|
60
|
+
def politely_say_they_are_wrong
|
61
|
+
@output_buffer.puts("Sorry, that's not it.")
|
62
|
+
end
|
63
|
+
|
64
|
+
def display_you_are_correct
|
65
|
+
@output_buffer.puts("Correct! Next up...")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Player Starts the Quiz
|
2
|
+
As a player
|
3
|
+
I want to start the quiz
|
4
|
+
So that I can proceed to Ruby Warrior
|
5
|
+
|
6
|
+
Scenario: start quiz
|
7
|
+
Given I am not playing
|
8
|
+
When I start a new quiz
|
9
|
+
Then I should see the Gates of Moria
|
10
|
+
And I should be prompted for the answer to the first question
|
11
|
+
|
12
|
+
Scenario: user answers first question correctly
|
13
|
+
Given I am not playing
|
14
|
+
When I start a new quiz
|
15
|
+
When I answer the first question correctly
|
16
|
+
Then I should not see the first help text
|
17
|
+
And I should see that I was correct
|
18
|
+
And I should be prompted for the answer to the second question
|
19
|
+
|
20
|
+
Scenario: user answers first question incorrectly
|
21
|
+
Given I am not playing
|
22
|
+
When I start a new quiz
|
23
|
+
And I answer the first question incorrectly
|
24
|
+
Then I should see the first help text
|
@@ -0,0 +1,46 @@
|
|
1
|
+
step 'I am not playing' do
|
2
|
+
end
|
3
|
+
|
4
|
+
step 'I start a new quiz' do
|
5
|
+
# simulate a game playing input/output session:
|
6
|
+
@output = StringIO.new
|
7
|
+
@input = StringIO.new
|
8
|
+
@motd = 'gates'
|
9
|
+
|
10
|
+
@quiz = GatesOfMoria::Quiz.new(@output, @input, @motd)
|
11
|
+
@quiz.start
|
12
|
+
end
|
13
|
+
|
14
|
+
step 'I should see the Gates of Moria' do
|
15
|
+
@output.string.should include(@motd)
|
16
|
+
end
|
17
|
+
|
18
|
+
step 'I should be prompted for the answer to the first question' do
|
19
|
+
@output.string.should include("Let me know your name by assigning it to a variable called '@name'!")
|
20
|
+
end
|
21
|
+
|
22
|
+
step 'I should be prompted for the answer to the second question' do
|
23
|
+
@output.string.should include("Now send the string 'sevraq' to the translate method.")
|
24
|
+
end
|
25
|
+
|
26
|
+
step 'I answer the first question correctly' do
|
27
|
+
step 'I should be prompted for the answer to the first question'
|
28
|
+
@input.gets "name = 'Matt'"
|
29
|
+
end
|
30
|
+
|
31
|
+
step 'I answer the first question incorrectly' do
|
32
|
+
step 'I should be prompted for the answer to the first question'
|
33
|
+
@input.gets "moo = 'baz'"
|
34
|
+
end
|
35
|
+
|
36
|
+
step "I should see the first help text" do
|
37
|
+
@output.string.should include("Variables hold information. We use the equal sign to assign information into a variable:\n@name = \"Matt\"")
|
38
|
+
end
|
39
|
+
|
40
|
+
step "I should not see the first help text" do
|
41
|
+
@output.string.should_not include("Variables hold information. We use the equal sign to assign information into a variable:\n@name = \"Matt\"")
|
42
|
+
end
|
43
|
+
|
44
|
+
step "I should see that I was correct" do
|
45
|
+
@output.string.should include("Correct!")
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GatesOfMoria
|
4
|
+
describe Quiz do
|
5
|
+
context 'starting up' do
|
6
|
+
it 'should send a welcome message' do
|
7
|
+
input_buffer = mock('input_buffer').as_null_object
|
8
|
+
output_buffer = mock('output_buffer').as_null_object
|
9
|
+
|
10
|
+
output_buffer.should_receive(:puts).with('gates')
|
11
|
+
|
12
|
+
game = GatesOfMoria::Quiz.new(output_buffer, input_buffer, 'gates')
|
13
|
+
game.start
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GatesOfMoria
|
4
|
+
describe REPL do
|
5
|
+
describe '#answer_question' do
|
6
|
+
let(:questions) { File.read('spec/fixtures/one_question.json') }
|
7
|
+
let(:output) { mock('output').as_null_object }
|
8
|
+
let(:input) { mock('input').as_null_object }
|
9
|
+
let(:expected_answer) { '@a == 5' }
|
10
|
+
|
11
|
+
context 'given correct answer' do
|
12
|
+
|
13
|
+
it 'should be true (correct)' do
|
14
|
+
repl = GatesOfMoria::REPL.new(output, input, questions)
|
15
|
+
user_input = "@a = 5"
|
16
|
+
repl.answer_question(expected_answer, user_input).should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'given wrong answer' do
|
21
|
+
it 'should be false (incorrect)' do
|
22
|
+
repl = GatesOfMoria::REPL.new(output, input, questions)
|
23
|
+
user_input = "@a = 1"
|
24
|
+
repl.answer_question(expected_answer, user_input).should be_false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'given invalid ruby' do
|
29
|
+
["foo", "foo = ", "lambda { ", ")"].each do |user_input|
|
30
|
+
it 'should be false (incorrect)' do
|
31
|
+
repl = GatesOfMoria::REPL.new(output, input, questions)
|
32
|
+
repl.answer_question(expected_answer, user_input).should be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gates_of_moria
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Gauger
|
9
|
+
- Jaymes Waters
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.11.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.11.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: turnip
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
description: A simple quiz to test Ruby knowledge
|
64
|
+
email:
|
65
|
+
- matt@bendyworks.com
|
66
|
+
executables:
|
67
|
+
- gates_of_moria
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- .gitignore
|
72
|
+
- .rspec
|
73
|
+
- .rvmrc
|
74
|
+
- Gemfile
|
75
|
+
- LICENSE.txt
|
76
|
+
- README.md
|
77
|
+
- Rakefile
|
78
|
+
- bin/gates_of_moria
|
79
|
+
- gates_of_moria.gemspec
|
80
|
+
- lib/gates_of_moria.rb
|
81
|
+
- lib/gates_of_moria/motd.txt
|
82
|
+
- lib/gates_of_moria/questions.json
|
83
|
+
- lib/gates_of_moria/quiz.rb
|
84
|
+
- lib/gates_of_moria/repl.rb
|
85
|
+
- lib/gates_of_moria/version.rb
|
86
|
+
- spec/acceptance/player_starts_the_quiz.feature
|
87
|
+
- spec/acceptance/steps/player_steps.rb
|
88
|
+
- spec/fixtures/one_question.json
|
89
|
+
- spec/gates_of_moria/quiz_spec.rb
|
90
|
+
- spec/gates_of_moria/repl_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/mathias/gates_of_moria
|
93
|
+
licenses: []
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.24
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: A simple quiz to test Ruby knowledge
|
116
|
+
test_files:
|
117
|
+
- spec/acceptance/player_starts_the_quiz.feature
|
118
|
+
- spec/acceptance/steps/player_steps.rb
|
119
|
+
- spec/fixtures/one_question.json
|
120
|
+
- spec/gates_of_moria/quiz_spec.rb
|
121
|
+
- spec/gates_of_moria/repl_spec.rb
|
122
|
+
- spec/spec_helper.rb
|