rails-girls-sofia-tryruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d3d8a5f5d94e730f32ebac378edb66b8193f1757
4
+ data.tar.gz: 8713d7267cb9b67c0a9cb2772c61944f9065c38d
5
+ SHA512:
6
+ metadata.gz: aa4facdec9aee37c8ef22180e09b10bb5af7d77ffb916104ea72250d315da557a2ee8a52757194f9ed0e3219b7c6f1edf306cc96fe544dc668f0bd4d409df0b8
7
+ data.tar.gz: 8764d33e79528504c76cd05f4f6a72656e20ca078c050d1d753a315626fb8614195120b2ffa82e9ce9b1eda9e3cd414901d63dc90ce98b10eb3cee73b1ea64be
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tryruby.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tony Pitale
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,34 @@
1
+ # Tryruby
2
+
3
+ TryRuby is a gem repl version of the wonderful website tryruby.org
4
+
5
+ [![Build Status](https://travis-ci.org/tpitale/tryruby.png?branch=master)](https://travis-ci.org/tpitale/tryruby)
6
+ [![Code Climate](https://codeclimate.com/github/tpitale/tryruby.png)](https://codeclimate.com/github/tpitale/tryruby)
7
+
8
+ ## Installation
9
+
10
+ gem install tryruby
11
+
12
+ And then execute to run through the exercise:
13
+
14
+ $ tryruby
15
+
16
+ ## TODO
17
+
18
+ * Remember the command history
19
+ * Print out all the work done at the end
20
+ * Create multiple levels of learning
21
+ * Expand what the REPL can do and teach
22
+ * Loadable DSL for scripts to teach aspects of ruby
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
31
+
32
+ If you get something committed, feel free to ask for commit rights!
33
+
34
+ Thanks!
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/bin/tryruby ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tryruby'
3
+
4
+ TryRuby::CLI.new(ARGV).run
5
+
6
+ # add -Ilib to run during development
data/lib/try_ruby.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "optparse"
2
+ require "readline"
3
+ require "json"
4
+
5
+ require "try_ruby/version"
6
+ require "try_ruby/message"
7
+ require "try_ruby/script"
8
+ require "try_ruby/repl"
9
+ require "try_ruby/cli"
10
+
11
+ module TryRuby
12
+ end
@@ -0,0 +1,55 @@
1
+ module TryRuby
2
+ class CLI
3
+ attr_accessor :options
4
+
5
+ def initialize(args)
6
+ self.options = parse_options(args)
7
+ end
8
+
9
+ def run
10
+ TryRuby::REPL.new(options).start
11
+ end
12
+
13
+ private
14
+
15
+ # @private
16
+ def parse_options(args)
17
+ {}.tap do |options|
18
+
19
+ OptionParser.new do |opts|
20
+ opts.banner = "Usage: tryruby [options]"
21
+
22
+ # opts.on('-o', '--output DIRECTORY', 'Require the DIRECTORY to download into.') do |dir|
23
+ # options[:directory] = dir
24
+ # end
25
+
26
+ # opts.on('-p', '--path [PATH]', 'Path inside Put.io to download from.') do |path|
27
+ # options[:filter_path] = path
28
+ # end
29
+
30
+ # opts.on('-e', '--extension [EXTENSION]', 'File extension to filter and download.') do |ext|
31
+ # options[:filter_extension] = ext
32
+ # end
33
+
34
+ # opts.on('-m', '--move [PATH]', 'After downloading, move the file to this path on Put.io.') do |path|
35
+ # options[:move_to] = path
36
+ # end
37
+
38
+ # opts.on('--delete', 'After downloading, remove the file from Put.io. BE CAREFUL') do
39
+ # options[:delete] = true
40
+ # end
41
+
42
+ # opts.on('--reset', 'Reset the time since last downloaded. This will redownload anything that is not in the downloads directory.') do
43
+ # options[:reset_last_accessed_at] = true
44
+ # end
45
+
46
+ opts.on_tail("-h", "--help", "Show this message") do
47
+ puts opts
48
+ exit
49
+ end
50
+ end.parse!(args)
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,14 @@
1
+ module TryRuby
2
+ Message = Struct.new(:title, :body, :continue) do
3
+
4
+ def initialize(attributes={})
5
+ super(*attributes.values_at(*members.map(&:to_s)))
6
+ end
7
+
8
+ alias :continue? :continue
9
+
10
+ def formatted
11
+ [title, body]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ module TryRuby
2
+ class REPL
3
+ def initialize(options={})
4
+ @options = options
5
+ end
6
+
7
+ def script
8
+ @script ||= Script.new("scripts/default.json")
9
+ end
10
+
11
+ def start
12
+ display "Hello! Interactive ruby ready."
13
+ display script.intro.formatted
14
+
15
+ while command = Readline.readline("> ", true)
16
+ case command
17
+ when "help"
18
+ display "Soon, I will have help for you."
19
+ when "next", "continue"
20
+ display script.next.formatted
21
+ when "prev", "previous", "back"
22
+ display script.previous.formatted
23
+ when "exit", "quit"
24
+ break
25
+ else
26
+ process(command)
27
+ end
28
+ end
29
+
30
+ display "Goodbye, I hope you had fun!\n"
31
+ end
32
+
33
+ def process(command)
34
+ begin
35
+ result = eval(command)
36
+
37
+ display "=> #{result}"
38
+
39
+ display(script.next.formatted) if script.continue?
40
+ rescue SyntaxError
41
+ display "Oops, seems to have been some error. Care to try again?"
42
+ rescue NameError
43
+ display "Oops, you tried to use a method or variable that doesn't exist. Care to try again?"
44
+ end
45
+ end
46
+
47
+ def display(message)
48
+ puts message
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ module TryRuby
2
+ class Script
3
+ attr_reader :position
4
+
5
+ def initialize(filename)
6
+ @position = 0
7
+
8
+ @script = JSON.parse(File.read(filename))
9
+ end
10
+
11
+ def messages
12
+ @messages ||= @script["messages"].map {|attributes| Message.new(attributes)}
13
+ end
14
+
15
+ def current_message
16
+ messages[@position]
17
+ end
18
+
19
+ alias :current :current_message
20
+
21
+ def length
22
+ messages.length
23
+ end
24
+
25
+ def continue?
26
+ current_message.continue?
27
+ end
28
+
29
+ def intro
30
+ messages.first
31
+ end
32
+
33
+ def outro
34
+ messages.last
35
+ end
36
+
37
+ def last?
38
+ @position == (length-1)
39
+ end
40
+
41
+ def first?
42
+ @position == 0
43
+ end
44
+
45
+ def next
46
+ @position += 1 unless last?
47
+ current
48
+ end
49
+
50
+ def previous
51
+ @position -= 1 unless first?
52
+ current
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module TryRuby
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tryruby.rb ADDED
@@ -0,0 +1 @@
1
+ require 'try_ruby'
@@ -0,0 +1,227 @@
1
+ {
2
+
3
+ "messages": [
4
+ {
5
+ "title": "Got 15 minutes? Give Ruby a shot right now!",
6
+ "body": "Ruby is a programming language from Japan (available at ruby-lang.org) which is revolutionizing the web. The beauty of Ruby is found in its balance between simplicity and power.\nTry out Ruby code in the prompt on the right. In addition to Ruby's built-in methods, the following commands are available:\nhelp → Start the 15 minute interactive tutorial. Trust me, it's very basic!\nclear → Clear screen. Useful if your browser starts slowing down. Your command history will be remembered.\nnext → Allows you to skip to the next section of a lesson.\nback → Allows you to skip to the previous section of a lesson.",
7
+ "continue": false
8
+ },
9
+ {
10
+ "title": "Using the Prompt",
11
+ "body": "The window to the right is a Ruby prompt.\nType a line of Ruby code, hit Enter and watch it run!\nFor example, try typing some math. Like: 2 + 6",
12
+ "continue": true
13
+ },
14
+ {
15
+ "title": "Using the Prompt",
16
+ "body": "Good! You did a bit of math. See how the answer popped out?\nRuby recognizes numbers and mathematic symbols. You could try some other math like:\n4 * 10\n5 - 12\n40 / 4",
17
+ "continue": false
18
+ },
19
+ {
20
+ "title": "Say Your Name",
21
+ "body": "Sure, computers are handy and fast for math.\nLet's move on. Want to see your name reversed?\nType your first name in quotes like this: \"Jimmy\"",
22
+ "continue": true
23
+
24
+ },
25
+ {
26
+ "title": "Say Your Name Reversed",
27
+ "body": "Perfect, you've formed a string from the letters of your name. A string is a set of characters the computer can process.\nImagine the letters are on a string of laundry line and the quotes are clothespins holding the ends. The quotes mark the beginning and end.\nTo reverse your name, type: \"Jimmy\".reverse (Don't forget the dot!)",
28
+ "continue": true
29
+
30
+ },
31
+ {
32
+ "title": "Counting the Letters",
33
+ "body": "You have used the reverse method on your name!\nBy enclosing your name in quotes, you made a string. Then you called the reverse method, which works on strings to flip all the letters backwards.\nNow, let's see how many letters are in your name: \"Jimmy\".length",
34
+ "continue": true
35
+ },
36
+ {
37
+ "title": "On Repeat",
38
+ "body": "Now, I'm sure by now you're wondering what any of this is good for. Well, I'm sure you've been to a website that screamed, Hey, your password is too short! See, some programs use this simple code.\nWatch this. Let's multiply your name by 5. \"Jimmy\" * 5",
39
+ "continue": true
40
+ },
41
+ {
42
+ "title": "Hey, Summary #1 Already",
43
+ "body": "Let's look at what you've learned in the first minute.\nThe prompt. Typing code into the prompt gives you an answer from a red prompt. All code gives an answer.\nNumbers and strings are Ruby's math and text objects.\nMethods. You've used English-language methods like reverse and symbolic methods like * (the multiplication method.) Methods are actions!\nThis is the essence of your learning. Taking simple things, toying with them and turning them into new things. Feeling comfortable yet? I promise you are.\nOkay, let's do something uncomfortable. Try reversing a number: 40.reverse",
44
+ "continue": true
45
+ },
46
+ {
47
+ "title": "Stop, You're Barking Mad!",
48
+ "body": "You can't reverse the number forty. I guess you can hold your monitor up to the mirror, but reversing a number just doesn't make sense. Ruby has tossed an error message.\nRuby is telling you there is no method reverse for numbers.\nMaybe if you turn it into a string: 40.to_s.reverse.",
49
+ "continue": true
50
+ },
51
+ {
52
+ "title": "Boys are Different From Girls",
53
+ "body": "And numbers are different from strings. While you can use methods on any object in Ruby, some methods only work on certain types of things. But you can always convert between different types using Ruby's \"to\" methods.\nto_s converts things to strings.\nto_i converts things to integers (numbers.)\nto_a converts things to arrays.\nWhat are arrays?! They are lists. Type in a pair of brackets: [].",
54
+ "continue": true
55
+ },
56
+ {
57
+ "title": "Standing in Line",
58
+ "body": "Great, that's an empty list. Lists store things in order. Like standing in line for popcorn. You are behind someone and you wouldn't dream of pushing them aside, right? And the guy behind you, you've got a close eye on him, right?\nHere's a list for you. Lottery numbers: [12, 47, 35].",
59
+ "continue": true
60
+ },
61
+ {
62
+ "title": "One Raises Its Hand",
63
+ "body": "list of lottery numbers. Which one is the highest?\nTry: [12, 47, 35].max.",
64
+ "continue": true
65
+ },
66
+ {
67
+ "title": "Tucking a List Away",
68
+ "body": "Good, good. But it's annoying to have to retype that list, isn't it?\nLet's save our numbers inside a ticket like so: ticket = [12, 47, 35]",
69
+ "continue": true
70
+ },
71
+ {
72
+ "title": "Now Type Ticket",
73
+ "body": "Now type ticket",
74
+ "continue": true
75
+ },
76
+ {
77
+ "title": "Saved, Tucked Away",
78
+ "body": "Fantastic! You've hung on to your lotto numbers, tucking them away inside a variable called ticket.\nLet's put your lotto numbers in order, how about? Use: ticket.sort!\nWhen you want to move on, type next",
79
+ "continue": false
80
+ },
81
+ {
82
+ "title": "Summary #2 is Upon Us",
83
+ "body": "You had a list. You sorted the list. The ticket variable is now changed.\nDid you notice that the sort! method has a big, bright exclamation at the end? A lot of times Ruby methods shout like that if they change what the variable contains for good. It's nothin' special, just a mark.\nNow, look how your second minute went:\nErrors. If you try to reverse a number or do anything fishy, Ruby will skip the prompt and tell you so.\nArrays are lists for storing things in order.\nVariables save a thing and give it a name. You used the equals sign to do this.\nLike: ticket = [14, 37, 18].\nIn all there are eight lessons. You are two-eighths of the way there! This is simple stuff, don't you think? Good stuff up ahead.\nLet's change directions for a moment. I've stuffed a bit of poetry for you in a certain variable. Take a look. Type print poem",
84
+ "continue": true
85
+ },
86
+ {
87
+ "title": "Sadly, You Hate Toast Poetry",
88
+ "body": "Look, it's okay. You don't have to like it. Hack it up, be my guest.\nInstead of toast, go for a melon or something. Try this: poem['toast'] = 'honeydew'",
89
+ "continue": true
90
+ },
91
+ {
92
+ "title": "Sadly, You Hate Toast Poetry",
93
+ "body": "Now type print poem by itself to see the new poem.\nNotice how you only changed the first toast? The joke's on you, bread hater.\nWhen you want to move on, type next",
94
+ "continue": false
95
+ },
96
+ {
97
+ "title": "Ready, Aim",
98
+ "body": "The square brackets you just used are very common in Ruby. Remember, you typed: poem['toast'] = 'honeydew'. That box with the word toast has a square bracket on each side, see?\nThe two brackets are like sights used to line up a target. Exactly. These brackets mean, \"I am looking for ____.\" Ready, aim. Here you're looking for toast and swapping it out with fruit.\nHere's a question: what happens when we reverse this whole poem? poem.reverse",
99
+ "continue": true
100
+ },
101
+ {
102
+ "title": "Too Much Reversal",
103
+ "body": "Okay, sure. So the whole poem's been turned backwards, letter-by-letter. I really want to just reverse the lines, though. Move the last line up to first and the first line down to last. Backwards, but not that backwards.\nHere's how: poem.lines.to_a.reverse",
104
+ "continue": true
105
+ },
106
+ {
107
+ "title": "Ringlets of Chained Methods",
108
+ "body": "So what do you see? What happened there? You typed poem.lines.to_a.reverse and what happened?\nTwo things happened. You turned the poem into a list using lines.to_a. lines decides the way the string is split up, then to_a converted it into an Array. (To array.) Different methods, such as bytes and chars can be used in place of lines. By using lines, ruby will return each line of the poem.\nThen, you reversed that list. You had each line. You reversed them. That's it.\nLet's tack one more method on the end there: print poem.lines.to_a.reverse.join",
109
+ "continue": true
110
+ },
111
+ {
112
+ "title": "Of All the Summaries, #3 is Here Now",
113
+ "body": "Good show, my friend! The join method took that list of reversed lines and put them together into a string. (Sure, you could have also just used to_s.)\nReview time.\nExclamations. Methods may have exclamations (and also question marks) in their name. No big deal. Try: poem.include? \"my hand\"\nSquare brackets. Target and find things. Search and replace.\nChaining methods lets you get a lot more done. Break up a poem, reverse it, reassemble it: poem.lines.to_a.reverse.join\nAt this point, you may want to tinker with the poem a bit more. A complete list of all the String methods is here. Go ahead and try a few (such as poem.downcase or poem.delete.)\nWhen you're ready to move on, type: books = {}",
114
+ "continue": true
115
+ },
116
+ {
117
+ "title": "A Wee Blank Book",
118
+ "body": "",
119
+ "continue": true
120
+ },
121
+ {
122
+ "title": "",
123
+ "body": "",
124
+ "continue": true
125
+ },
126
+ {
127
+ "title": "",
128
+ "body": "",
129
+ "continue": true
130
+ },
131
+ {
132
+ "title": "",
133
+ "body": "",
134
+ "continue": true
135
+ },
136
+ {
137
+ "title": "",
138
+ "body": "",
139
+ "continue": true
140
+ },
141
+ {
142
+ "title": "",
143
+ "body": "",
144
+ "continue": true
145
+ },
146
+ {
147
+ "title": "",
148
+ "body": "",
149
+ "continue": true
150
+ },
151
+ {
152
+ "title": "",
153
+ "body": "",
154
+ "continue": true
155
+ },
156
+ {
157
+ "title": "",
158
+ "body": "",
159
+ "continue": true
160
+ },
161
+ {
162
+ "title": "",
163
+ "body": "",
164
+ "continue": true
165
+ },
166
+ {
167
+ "title": "",
168
+ "body": "",
169
+ "continue": true
170
+ },
171
+ {
172
+ "title": "",
173
+ "body": "",
174
+ "continue": true
175
+ },
176
+ {
177
+ "title": "",
178
+ "body": "",
179
+ "continue": true
180
+ },
181
+ {
182
+ "title": "",
183
+ "body": "",
184
+ "continue": true
185
+ },
186
+ {
187
+ "title": "",
188
+ "body": "",
189
+ "continue": true
190
+ },
191
+ {
192
+ "title": "",
193
+ "body": "",
194
+ "continue": true
195
+ },
196
+ {
197
+ "title": "",
198
+ "body": "",
199
+ "continue": true
200
+ },
201
+ {
202
+ "title": "",
203
+ "body": "",
204
+ "continue": true
205
+ },
206
+ {
207
+ "title": "",
208
+ "body": "",
209
+ "continue": true
210
+ },
211
+ {
212
+ "title": "",
213
+ "body": "",
214
+ "continue": true
215
+ },
216
+ {
217
+ "title": "",
218
+ "body": "",
219
+ "continue": true
220
+ },
221
+ {
222
+ "title": "",
223
+ "body": "",
224
+ "continue": true
225
+ }
226
+ ]
227
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+
3
+ "messages": [
4
+ {
5
+ "title": "Got 15 minutes? Give Ruby a shot right now!",
6
+ "body": "Ruby is a programming language from Japan.",
7
+ "continue": false
8
+ },
9
+ {
10
+ "title": "Using the Prompt",
11
+ "body": "The window to the right is a Ruby prompt.\nType a line of Ruby code, hit Enter and watch it run!\nFor example, try typing some math. Like: 2 + 6",
12
+ "continue": true
13
+ },
14
+ {
15
+ "title": "Of All the Summaries, #3 is Here Now",
16
+ "body": "Good show, my friend! The join method took that list of reversed lines and put them together into a string. (Sure, you could have also just used to_s.)\nReview time.\nExclamations. Methods may have exclamations (and also question marks) in their name. No big deal. Try: poem.include? \"my hand\"\nSquare brackets. Target and find things. Search and replace.\nChaining methods lets you get a lot more done. Break up a poem, reverse it, reassemble it: poem.lines.to_a.reverse.join\nAt this point, you may want to tinker with the poem a bit more. A complete list of all the String methods is here. Go ahead and try a few (such as poem.downcase or poem.delete.)\nWhen you're ready to move on, type: books = {}",
17
+ "continue": true
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe TryRuby::CLI do
4
+ context "a cli" do
5
+ let(:cli) {TryRuby::CLI.new([])}
6
+
7
+ it 'runs the repl with parsed options' do
8
+ repl = stub(:start)
9
+ TryRuby::REPL.stubs(:new).returns(repl)
10
+
11
+ cli.run
12
+
13
+ expect(repl).to have_received(:start)
14
+ expect(TryRuby::REPL).to have_received(:new).with({})
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe TryRuby::Message do
4
+ let(:message) {TryRuby::Message.new(title: 'Hello, and welcome!', body: 'This tutorial will help you learn ruby.')}
5
+
6
+ it 'returns title and body' do
7
+ title, body = message.formatted
8
+ expect(title).to eq(message.title)
9
+ expect(body).to eq(message.body)
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe TryRuby::REPL do
4
+
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe TryRuby::Script do
4
+ let(:script) {TryRuby::Script.new(File.expand_path('../../../fixtures/scripts/example.json', __FILE__))}
5
+
6
+ before(:each) do
7
+ end
8
+
9
+
10
+ it 'knows if the current position message should continue automatically' do
11
+ expect(script.continue?).to be(false)
12
+ script.next
13
+ expect(script.continue?).to be(true)
14
+ end
15
+
16
+ context "#next" do
17
+ it 'advances the position' do
18
+ expect(script.position).to eq(0)
19
+ script.next
20
+ expect(script.position).to eq(1)
21
+ end
22
+
23
+ it 'does not advance beyond the last message' do
24
+ expect(script.position).to eq(0)
25
+ script.length.times {script.next}
26
+ expect(script.position).to eq(script.length-1)
27
+ end
28
+ end
29
+
30
+ context "#previous" do
31
+ it 'prints the previous position body' do
32
+ expect(script.position).to eq(0)
33
+ script.next
34
+ script.next
35
+ script.previous
36
+ expect(script.position).to eq(1)
37
+ end
38
+
39
+ it 'does not reverse beyond the first message' do
40
+ expect(script.position).to eq(0)
41
+ script.previous
42
+ expect(script.position).to eq(0)
43
+ end
44
+ end
45
+
46
+ it 'has an intro message' do
47
+ expect(script.intro).to eq(script.messages.first)
48
+ end
49
+
50
+ it 'has an outro message' do
51
+ expect(script.outro).to eq(script.messages.last)
52
+ end
53
+ end
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'bundler/setup'
5
+
6
+ require 'rspec'
7
+ require 'mocha/api'
8
+ require 'bourne'
9
+
10
+ require File.expand_path('../../lib/try_ruby', __FILE__)
11
+
12
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
13
+ RSpec.configure do |config|
14
+ config.mock_with :mocha
15
+
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ # Run specs in random order to surface order dependencies. If you find an
21
+ # order dependency and want to debug it, you can fix the order by providing
22
+ # the seed, which is printed after each run.
23
+ # --seed 1234
24
+ config.order = 'random'
25
+ end
data/tryruby.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/try_ruby/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Tony Pitale"]
6
+ gem.email = ["tpitale@gmail.com"]
7
+ gem.description = %q{A gem REPL version of tryruby.org}
8
+ gem.summary = %q{A gem REPL version of tryruby.org}
9
+ gem.homepage = "http://tryruby.org"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(spec)/})
14
+ gem.name = "rails-girls-sofia-tryruby"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = TryRuby::VERSION
17
+
18
+ gem.add_development_dependency "bundler"
19
+ gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "mocha"
22
+ gem.add_development_dependency "bourne"
23
+ gem.add_development_dependency "simplecov"
24
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-girls-sofia-tryruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tony Pitale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bourne
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A gem REPL version of tryruby.org
98
+ email:
99
+ - tpitale@gmail.com
100
+ executables:
101
+ - tryruby
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - bin/tryruby
114
+ - lib/try_ruby.rb
115
+ - lib/try_ruby/cli.rb
116
+ - lib/try_ruby/message.rb
117
+ - lib/try_ruby/repl.rb
118
+ - lib/try_ruby/script.rb
119
+ - lib/try_ruby/version.rb
120
+ - lib/tryruby.rb
121
+ - scripts/default.json
122
+ - spec/fixtures/scripts/example.json
123
+ - spec/lib/try_ruby/cli_spec.rb
124
+ - spec/lib/try_ruby/message_spec.rb
125
+ - spec/lib/try_ruby/repl_spec.rb
126
+ - spec/lib/try_ruby/script_spec.rb
127
+ - spec/spec_helper.rb
128
+ - tryruby.gemspec
129
+ homepage: http://tryruby.org
130
+ licenses: []
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.2.2
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: A gem REPL version of tryruby.org
152
+ test_files:
153
+ - spec/fixtures/scripts/example.json
154
+ - spec/lib/try_ruby/cli_spec.rb
155
+ - spec/lib/try_ruby/message_spec.rb
156
+ - spec/lib/try_ruby/repl_spec.rb
157
+ - spec/lib/try_ruby/script_spec.rb
158
+ - spec/spec_helper.rb