├── .bundle └── config ├── .gitignore ├── .rspec ├── 00_hello ├── hello.rb ├── hello_spec.rb └── index.html ├── 01_temperature ├── index.html ├── temperature.rb └── temperature_spec.rb ├── 02_calculator ├── calculator.rb ├── calculator_spec.rb └── index.html ├── 03_simon_says ├── index.html ├── simon_says.rb └── simon_says_spec.rb ├── 04_pig_latin ├── index.html ├── pig_latin.rb └── pig_latin_spec.rb ├── 05_book_titles ├── book.rb ├── book_titles_spec.rb └── index.html ├── 06_timer ├── index.html ├── timer.rb └── timer_spec.rb ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── assets └── style.css ├── rspec_config.rb └── spec └── spec_helper.rb /.bundle/config: -------------------------------------------------------------------------------- 1 | --- {} 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | +.DS_Store* 3 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /00_hello/hello.rb: -------------------------------------------------------------------------------- 1 | #write your code here 2 | -------------------------------------------------------------------------------- /00_hello/hello_spec.rb: -------------------------------------------------------------------------------- 1 | # # Hello! 2 | # 3 | # This lab teaches basic Ruby function syntax. 4 | # 5 | # ## Open a terminal in this directory 6 | # 7 | # cd 00_hello 8 | # 9 | # This directory is the starting point for this exercise. It contains a spec file and a ruby file to (eventually) make the specs pass. 10 | # 11 | # ## Run the test 12 | # 13 | # rake 14 | # 15 | # ## Watch it fail 16 | # 17 | # you should see an error like this: 18 | # 19 | # the hello function 20 | # says hello (FAILED - 1) 21 | # 22 | # Failures: 23 | # 24 | # 1) the hello function says hello 25 | # Failure/Error: expect(hello).to eq("Hello!") 26 | # NameError: 27 | # undefined local variable or method `hello' for # 28 | # # ./hello/hello_spec.rb:5:in `block (2 levels) in ' 29 | # 30 | # ## Create the hello function 31 | # 32 | # Fix this by opening `hello.rb` and creating an empty function: 33 | # 34 | # def hello 35 | # end 36 | # 37 | # Save it. Run the test again. 38 | # 39 | # ## Watch it fail 40 | # 41 | # Now you should see an error like this: 42 | # 43 | # the hello function 44 | # says hello (FAILED - 1) 45 | # 46 | # Failures: 47 | # 48 | # 1) the hello function says hello 49 | # Failure/Error: expect(hello).to eq("Hello!") 50 | # expected: "Hello!" 51 | # got: nil (compared using ==) 52 | # # ./hello/hello_spec.rb:5:in `block (2 levels) in ' 53 | # 54 | # This means that while it found the file, and it found the function, it's not returning anything! ("nil" is the Ruby way of saying "not anything".) 55 | # 56 | # ## Make it return something 57 | # 58 | # Inside the "hello" function, put a single line containing a string that is *not* "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.) 59 | # 60 | # def hello 61 | # "whuh?" 62 | # end 63 | # 64 | # Save it. Run the test again. 65 | # 66 | # ## Watch it fail 67 | # 68 | # Now you should see an error like this: 69 | # 70 | # 1) the hello function says hello 71 | # Failure/Error: expect(hello.to eq("Hello!") 72 | # expected: "Hello!" 73 | # got: "whuh?" (compared using ==) 74 | # # ./hello/hello_spec.rb:5:in `block (2 levels) in ' 75 | # 76 | # Correct this by changing "whuh?" to "Hello!". Save it. Run the test again. 77 | # 78 | # ## Watch it pass! 79 | # 80 | # Hooray! Finally! It works! 81 | # 82 | # ## Give yourself a high five 83 | # 84 | # Also, sing a song and do a little dance. 85 | # 86 | # ## And then... 87 | # 88 | # Fix the next failure! `:-)` 89 | # 90 | # the hello function 91 | # says hello 92 | # 93 | # the greet function 94 | # says hello to someone (FAILED - 1) 95 | # 96 | # In order to get the next test to pass, your function will need to accept an *argument*. 97 | # 98 | # def greet(who) 99 | # "Hello, #{who}!" 100 | # end 101 | # 102 | require "hello" 103 | 104 | describe "the hello function" do 105 | it "says hello" do 106 | expect(hello).to eq("Hello!") 107 | end 108 | end 109 | 110 | describe "the greet function" do 111 | it "says hello to someone" do 112 | expect(greet("Alice")).to eq("Hello, Alice!") 113 | end 114 | 115 | it "says hello to someone else" do 116 | expect(greet("Bob")).to eq("Hello, Bob!") 117 | end 118 | end 119 | -------------------------------------------------------------------------------- /00_hello/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: hello 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

hello

25 |

Hello!

26 | 27 |

This lab teaches basic Ruby function syntax.

28 | 29 |

Open a terminal in this directory

30 | 31 |
cd 00_hello
 32 | 
33 | 34 |

This directory is the starting point for this exercise. It contains a spec file and a ruby file to (eventually) make the specs pass.

35 | 36 |

Run the test

37 | 38 |
rake
 39 | 
40 | 41 |

Watch it fail

42 | 43 |

you should see an error like this:

44 | 45 |
the hello function
 46 |   says hello (FAILED - 1)
 47 | 
 48 | Failures:
 49 | 
 50 |   1) the hello function says hello
 51 |      Failure/Error: expect(hello).to eq("Hello!")
 52 |      NameError:
 53 |        undefined local variable or method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808>
 54 |      # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
 55 | 
56 | 57 |

Create the hello function

58 | 59 |

Fix this by opening hello.rb and creating an empty function:

60 | 61 |
def hello
 62 | end
 63 | 
64 | 65 |

Save it. Run the test again.

66 | 67 |

Watch it fail

68 | 69 |

Now you should see an error like this:

70 | 71 |
the hello function
 72 |   says hello (FAILED - 1)
 73 | 
 74 | Failures:
 75 | 
 76 |   1) the hello function says hello
 77 |      Failure/Error: expect(hello).to eq("Hello!")
 78 |        expected: "Hello!"
 79 |             got: nil (compared using ==)
 80 |      # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
 81 | 
82 | 83 |

This means that while it found the file, and it found the function, it's not returning anything! ("nil" is the Ruby way of saying "not anything".)

84 | 85 |

Make it return something

86 | 87 |

Inside the "hello" function, put a single line containing a string that is not "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.)

88 | 89 |
def hello
 90 |   "whuh?"
 91 | end
 92 | 
93 | 94 |

Save it. Run the test again.

95 | 96 |

Watch it fail

97 | 98 |

Now you should see an error like this:

99 | 100 |
1) the hello function says hello
101 |    Failure/Error: expect(hello).to eq("Hello!")
102 |      expected: "Hello!"
103 |           got: "whuh?" (compared using ==)
104 |    # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
105 | 
106 | 107 |

Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.

108 | 109 |

Watch it pass!

110 | 111 |

Hooray! Finally! It works!

112 | 113 |

Give yourself a high five

114 | 115 |

Also, sing a song and do a little dance.

116 | 117 |

And then...

118 | 119 |

Fix the next failure! :-)

120 | 121 |
the hello function
122 |   says hello
123 | 
124 | the greet function
125 |   says hello to someone (FAILED - 1)
126 | 
127 | 128 |

In order to get the next test to pass, your function will need to accept an argument.

129 | 130 |
def greet(who)
131 |   "Hello, #{who}!"
132 | end
133 | 
134 |
135 |
136 |

Tests

137 | hello_spec.rb 138 |
require "hello"
139 | 
140 | describe "the hello function" do
141 |   it "says hello" do
142 |     expect(hello).to eq("Hello!")
143 |   end
144 | end
145 | 
146 | describe "the greet function" do
147 |   it "says hello to someone" do
148 |     expect(greet("Alice")).to eq("Hello, Alice!")
149 |   end
150 | 
151 |   it "says hello to someone else" do
152 |     expect(greet("Bob")).to eq("Hello, Bob!")
153 |   end
154 | end
155 |
156 |
157 |
158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /01_temperature/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: temperature 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

temperature

25 |

Topics:

26 | 27 |
    28 |
  • functions
  • 29 |
  • floating-point math
  • 30 |
31 | 32 | 33 |

Hints

34 | 35 |

Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit.

36 | 37 |

In integer math, there are no fractions. So if you are using integer literals, you will be using integer math, which means, for example...

38 | 39 |

1 / 2 => 0

40 | 41 |

In floating point math, there are fractions. So...

42 | 43 |

1.0 / 2.0 => 0.5

44 |
45 |
46 |

Tests

47 | temperature_spec.rb 48 |
 49 | require "temperature"
 50 | 
 51 | describe "temperature conversion functions" do
 52 | 
 53 |   describe "#ftoc" do
 54 | 
 55 |     it "converts freezing temperature" do
 56 |       expect(ftoc(32)).to eq(0)
 57 |     end
 58 | 
 59 |     it "converts boiling temperature" do
 60 |       expect(ftoc(212)).to eq(100)
 61 |     end
 62 | 
 63 |     it "converts body temperature" do
 64 |       expect(ftoc(98.6)).to eq(37)
 65 |     end
 66 | 
 67 |     it "converts arbitrary temperature" do
 68 |       expect(ftoc(68)).to eq(20)
 69 |     end
 70 | 
 71 |   end
 72 | 
 73 |   describe "#ctof" do
 74 | 
 75 |     it "converts freezing temperature" do
 76 |       expect(ctof(0)).to eq(32)
 77 |     end
 78 | 
 79 |     it "converts boiling temperature" do
 80 |       expect(ctof(100)).to eq(212)
 81 |     end
 82 | 
 83 |     it "converts arbitrary temperature" do
 84 |       expect(ctof(20)).to eq(68)
 85 |     end
 86 | 
 87 |     it "converts body temperature" do
 88 |       expect(ctof(37)).to be_within(0.1).of(98.6)
 89 |       # Why do we need to use be_within?
 90 |       # See http://www.ruby-forum.com/topic/169330
 91 |       # and http://en.wikipedia.org/wiki/IEEE_754-2008
 92 |       # and http://en.wikipedia.org/wiki/Double_precision_floating-point_format
 93 |       # Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right?
 94 |     end
 95 | 
 96 |   end
 97 | 
 98 | end
99 |
100 |
101 |
102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /01_temperature/temperature.rb: -------------------------------------------------------------------------------- 1 | #write your code here 2 | -------------------------------------------------------------------------------- /01_temperature/temperature_spec.rb: -------------------------------------------------------------------------------- 1 | # # Topics: 2 | # * functions 3 | # * floating-point math 4 | # 5 | # # Hints 6 | # 7 | # Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit. 8 | # 9 | # In integer math, there **are no fractions**. So if you are using integer literals, you will be using integer math, which means, for example... 10 | # 11 | # 1 / 2 => 0 12 | # 13 | # In floating point math, there **are** fractions. So... 14 | # 15 | # 1.0 / 2.0 => 0.5 16 | # 17 | 18 | require "temperature" 19 | 20 | describe "temperature conversion functions" do 21 | 22 | describe "#ftoc" do 23 | 24 | it "converts freezing temperature" do 25 | expect(ftoc(32)).to eq(0) 26 | end 27 | 28 | it "converts boiling temperature" do 29 | expect(ftoc(212)).to eq(100) 30 | end 31 | 32 | it "converts body temperature" do 33 | expect(ftoc(98.6)).to eq(37) 34 | end 35 | 36 | it "converts arbitrary temperature" do 37 | expect(ftoc(68)).to eq(20) 38 | end 39 | 40 | end 41 | 42 | describe "#ctof" do 43 | 44 | it "converts freezing temperature" do 45 | expect(ctof(0)).to eq(32) 46 | end 47 | 48 | it "converts boiling temperature" do 49 | expect(ctof(100)).to eq(212) 50 | end 51 | 52 | it "converts arbitrary temperature" do 53 | expect(ctof(20)).to eq(68) 54 | end 55 | 56 | it "converts body temperature" do 57 | expect(ctof(37)).to be_within(0.1).of(98.6) 58 | # Why do we need to use be_within? 59 | # See http://www.ruby-forum.com/topic/169330 60 | # and http://en.wikipedia.org/wiki/IEEE_754-2008 61 | # and http://en.wikipedia.org/wiki/Double_precision_floating-point_format 62 | # Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right? 63 | end 64 | 65 | end 66 | 67 | end 68 | -------------------------------------------------------------------------------- /02_calculator/calculator.rb: -------------------------------------------------------------------------------- 1 | #write your code here 2 | -------------------------------------------------------------------------------- /02_calculator/calculator_spec.rb: -------------------------------------------------------------------------------- 1 | # # Topics 2 | # 3 | # * functions 4 | # * math 5 | # * arrays 6 | # * iterating/looping 7 | # 8 | # # Calculator 9 | # 10 | # you will build a simple calculator script with the following methods: 11 | # 12 | # `add` takes two parameters and adds them 13 | # 14 | # `subtract` takes two parameters and subtracts the second from the first 15 | # 16 | # `sum` takes an *array* of parameters and adds them all together 17 | # 18 | # # Warning 19 | # 20 | # You may not have enough knowledge yet to complete `sum`. You will probably 21 | # need to use **loops** (e.g. `while`) or **iterators** (e.g. `each`) to 22 | # get the tests to pass. 23 | # 24 | # # Bonus 25 | # 26 | # There are also some bonus exercises for when you finish the regular ones. The bonus round will help teach you test-driven *development*, not simply test-guided *learning*. 27 | # 28 | # Your mission, should you choose to accept it, is to write *tests* for three new methods: 29 | # 30 | # * `multiply` which multiplies two numbers together 31 | # * `power` which raises one number to the power of another number 32 | # * `[factorial](http://en.wikipedia.org/wiki/Factorial)` (check Wikipedia if you forgot your high school math). 33 | # 34 | # 35 | 36 | require "calculator" 37 | 38 | describe "add" do 39 | it "adds 0 and 0" do 40 | expect(add(0,0)).to eq(0) 41 | end 42 | 43 | it "adds 2 and 2" do 44 | expect(add(2,2)).to eq(4) 45 | end 46 | 47 | it "adds positive numbers" do 48 | expect(add(2,6)).to eq(8) 49 | end 50 | end 51 | 52 | describe "subtract" do 53 | it "subtracts numbers" do 54 | expect(subtract(10,4)).to eq(6) 55 | end 56 | end 57 | 58 | describe "sum" do 59 | it "computes the sum of an empty array" do 60 | expect(sum([])).to eq(0) 61 | end 62 | 63 | it "computes the sum of an array of one number" do 64 | expect(sum([7])).to eq(7) 65 | end 66 | 67 | it "computes the sum of an array of two numbers" do 68 | expect(sum([7,11])).to eq(18) 69 | end 70 | 71 | it "computes the sum of an array of many numbers" do 72 | expect(sum([1,3,5,7,9])).to eq(25) 73 | end 74 | end 75 | 76 | # Extra Credit Test-Driving Bonus: 77 | # once the above tests pass, 78 | # write tests and code for the following: 79 | 80 | describe "#multiply" do 81 | 82 | it "multiplies two numbers" 83 | 84 | it "multiplies several numbers" 85 | 86 | end 87 | 88 | describe "#power" do 89 | it "raises one number to the power of another number" 90 | end 91 | 92 | # http://en.wikipedia.org/wiki/Factorial 93 | describe "#factorial" do 94 | it "computes the factorial of 0" 95 | it "computes the factorial of 1" 96 | it "computes the factorial of 2" 97 | it "computes the factorial of 5" 98 | it "computes the factorial of 10" 99 | end 100 | -------------------------------------------------------------------------------- /02_calculator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: calculator 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

calculator

25 |

Topics

26 | 27 |
    28 |
  • functions
  • 29 |
  • math
  • 30 |
  • arrays
  • 31 |
  • iterating/looping
  • 32 |
33 | 34 | 35 |

Calculator

36 | 37 |

you will build a simple calculator script with the following methods:

38 | 39 |

add takes two parameters and adds them

40 | 41 |

subtract takes two parameters and subtracts the second from the first

42 | 43 |

sum takes an array of parameters and adds them all together

44 | 45 |

Warning

46 | 47 |

You may not have enough knowledge yet to complete sum. You will probably 48 | need to use loops (e.g. while) or iterators (e.g. each) to 49 | get the tests to pass.

50 | 51 |

Bonus

52 | 53 |

There are also some bonus exercises for when you finish the regular ones. The bonus round will help teach you test-driven development, not simply test-guided learning.

54 | 55 |

Your mission, should you choose to accept it, is to write tests for three new methods:

56 | 57 |
    58 |
  • multiply which multiplies two numbers together
  • 59 |
  • power which raises one number to the power of another number
  • 60 |
  • [factorial](http://en.wikipedia.org/wiki/Factorial) (check Wikipedia if you forgot your high school math).
  • 61 |
62 | 63 |
64 |
65 |

Tests

66 | calculator_spec.rb 67 |
 68 | require "calculator"
 69 | 
 70 | describe "add" do
 71 |   it "adds 0 and 0" do
 72 |     expect(add(0,0)).to eq(0)
 73 |   end
 74 | 
 75 |   it "adds 2 and 2" do
 76 |     expect(add(2,2)).to eq(4)
 77 |   end
 78 | 
 79 |   it "adds positive numbers" do
 80 |     expect(add(2,6)).to eq(8)
 81 |   end
 82 | end
 83 | 
 84 | describe "subtract" do
 85 |   it "subtracts numbers" do
 86 |     expect(subtract(10,4)).to eq(6)
 87 |   end
 88 | end
 89 | 
 90 | describe "sum" do
 91 |   it "computes the sum of an empty array" do
 92 |     expect(sum([])).to eq(0)
 93 |   end
 94 | 
 95 |   it "computes the sum of an array of one number" do
 96 |     expect(sum([7])).to eq(7)
 97 |   end
 98 | 
 99 |   it "computes the sum of an array of two numbers" do
100 |     expect(sum([7,11])).to eq(18)
101 |   end
102 | 
103 |   it "computes the sum of an array of many numbers" do
104 |     expect(sum([1,3,5,7,9])).to eq(25)
105 |   end
106 | end
107 | 
108 | # Extra Credit Test-Driving Bonus:
109 | # once the above tests pass,
110 | # write tests and code for the following:
111 | 
112 | describe "#multiply" do
113 | 
114 |   it "multiplies two numbers"
115 | 
116 |   it "multiplies several numbers"
117 | 
118 | end
119 | 
120 | describe "#power" do
121 |   it "raises one number to the power of another number"
122 | end
123 | 
124 | # http://en.wikipedia.org/wiki/Factorial
125 | describe "#factorial" do
126 |   it "computes the factorial of 0"
127 |   it "computes the factorial of 1"
128 |   it "computes the factorial of 2"
129 |   it "computes the factorial of 5"
130 |   it "computes the factorial of 10"
131 | end
132 |
133 |
134 |
135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /03_simon_says/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: simon_says 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

simon_says

25 |

Simon Says

26 | 27 |

Topics

28 | 29 |
    30 |
  • functions
  • 31 |
  • strings
  • 32 |
  • default parameter values
  • 33 |
34 | 35 | 36 |

Hints

37 | 38 |

When you make the second repeat test pass, you might break the first

39 |
40 |
41 |

Tests

42 | simon_says_spec.rb 43 |
 44 | require "simon_says"
 45 | 
 46 | describe "Simon says" do
 47 |   describe "echo" do
 48 |     it "should echo hello" do
 49 |       expect(echo("hello")).to eq("hello")
 50 |     end
 51 | 
 52 |     it "should echo bye" do
 53 |       expect(echo("bye")).to eq("bye")
 54 |     end
 55 |   end
 56 | 
 57 |   describe "shout" do
 58 |     it "should shout hello" do
 59 |       expect(shout("hello")).to eq("HELLO")
 60 |     end
 61 | 
 62 |     it "should shout multiple words" do
 63 |       expect(shout("hello world")).to eq("HELLO WORLD")
 64 |     end
 65 |   end
 66 | 
 67 |   describe "repeat" do
 68 |     it "should repeat" do
 69 |       expect(repeat("hello")).to eq("hello hello")
 70 |     end
 71 | 
 72 |     # Wait a second! How can you make the "repeat" method
 73 |     # take one *or* two arguments?
 74 |     #
 75 |     # Hint: *default values*
 76 |     it "should repeat a number of times" do
 77 |       expect(repeat("hello", 3)).to eq("hello hello hello")
 78 |     end
 79 |   end
 80 | 
 81 |   describe "start_of_word" do
 82 |     it "returns the first letter" do
 83 |       expect(start_of_word("hello", 1)).to eq("h")
 84 |     end
 85 | 
 86 |     it "returns the first two letters" do
 87 |       expect(start_of_word("Bob", 2)).to eq("Bo")
 88 |     end
 89 | 
 90 |     it "returns the first several letters" do
 91 |       s = "abcdefg"
 92 |       expect(start_of_word(s, 1)).to eq("a")
 93 |       expect(start_of_word(s, 2)).to eq("ab")
 94 |       expect(start_of_word(s, 3)).to eq("abc")
 95 |     end
 96 |   end
 97 | 
 98 |   describe "first_word" do
 99 |     it "tells us the first word of 'Hello World' is 'Hello'" do
100 |       expect(first_word("Hello World")).to eq("Hello")
101 |     end
102 | 
103 |     it "tells us the first word of 'oh dear' is 'oh'" do
104 |       expect(first_word("oh dear")).to eq("oh")
105 |     end
106 |   end
107 | 
108 |   describe "titleize" do
109 |     it "capitalizes a word" do
110 |       expect(titleize("jaws")).to eq("Jaws")
111 |     end
112 | 
113 |     it "capitalizes every word (aka title case)" do
114 |       expect(titleize("david copperfield")).to eq("David Copperfield")
115 |     end
116 | 
117 |     it "doesn't capitalize 'little words' in a title" do
118 |       expect(titleize("war and peace")).to eq("War and Peace")
119 |     end
120 | 
121 |     it "does capitalize 'little words' at the start of a title" do
122 |       expect(titleize("the bridge over the river kwai")).to eq("The Bridge over the River Kwai")
123 |     end
124 |   end
125 | 
126 | end
127 |
128 |
129 |
130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /03_simon_says/simon_says.rb: -------------------------------------------------------------------------------- 1 | #write your code here 2 | -------------------------------------------------------------------------------- /03_simon_says/simon_says_spec.rb: -------------------------------------------------------------------------------- 1 | # # Simon Says 2 | # 3 | # ## Topics 4 | # 5 | # * functions 6 | # * strings 7 | # * default parameter values 8 | # 9 | # ## Hints 10 | # 11 | # When you make the second `repeat` test pass, you might break the **first** 12 | # 13 | 14 | require "simon_says" 15 | 16 | describe "Simon says" do 17 | describe "echo" do 18 | it "should echo hello" do 19 | expect(echo("hello")).to eq("hello") 20 | end 21 | 22 | it "should echo bye" do 23 | expect(echo("bye")).to eq("bye") 24 | end 25 | end 26 | 27 | describe "shout" do 28 | it "should shout hello" do 29 | expect(shout("hello")).to eq("HELLO") 30 | end 31 | 32 | it "should shout multiple words" do 33 | expect(shout("hello world")).to eq("HELLO WORLD") 34 | end 35 | end 36 | 37 | describe "repeat" do 38 | it "should repeat" do 39 | expect(repeat("hello")).to eq("hello hello") 40 | end 41 | 42 | # Wait a second! How can you make the "repeat" method 43 | # take one *or* two arguments? 44 | # 45 | # Hint: *default values* 46 | it "should repeat a number of times" do 47 | expect(repeat("hello", 3)).to eq("hello hello hello") 48 | end 49 | end 50 | 51 | describe "start_of_word" do 52 | it "returns the first letter" do 53 | expect(start_of_word("hello", 1)).to eq("h") 54 | end 55 | 56 | it "returns the first two letters" do 57 | expect(start_of_word("Bob", 2)).to eq("Bo") 58 | end 59 | 60 | it "returns the first several letters" do 61 | s = "abcdefg" 62 | expect(start_of_word(s, 1)).to eq("a") 63 | expect(start_of_word(s, 2)).to eq("ab") 64 | expect(start_of_word(s, 3)).to eq("abc") 65 | end 66 | end 67 | 68 | describe "first_word" do 69 | it "tells us the first word of 'Hello World' is 'Hello'" do 70 | expect(first_word("Hello World")).to eq("Hello") 71 | end 72 | 73 | it "tells us the first word of 'oh dear' is 'oh'" do 74 | expect(first_word("oh dear")).to eq("oh") 75 | end 76 | end 77 | 78 | describe "titleize" do 79 | it "capitalizes a word" do 80 | expect(titleize("jaws")).to eq("Jaws") 81 | end 82 | 83 | it "capitalizes every word (aka title case)" do 84 | expect(titleize("david copperfield")).to eq("David Copperfield") 85 | end 86 | 87 | it "doesn't capitalize 'little words' in a title" do 88 | expect(titleize("war and peace")).to eq("War and Peace") 89 | end 90 | 91 | it "does capitalize 'little words' at the start of a title" do 92 | expect(titleize("the bridge over the river kwai")).to eq("The Bridge over the River Kwai") 93 | end 94 | end 95 | 96 | end 97 | -------------------------------------------------------------------------------- /04_pig_latin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: pig_latin 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

pig_latin

25 |

Topics

26 | 27 |
    28 |
  • modules
  • 29 |
  • strings
  • 30 |
31 | 32 | 33 |

Pig Latin

34 | 35 |

Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand.

36 | 37 |

Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.

38 | 39 |

Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word.

40 | 41 |

(There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)

42 | 43 |

See http://en.wikipedia.org/wiki/Pig_latin for more details.

44 |
45 |
46 |

Tests

47 | pig_latin_spec.rb 48 |
 49 | require "pig_latin"
 50 | 
 51 | describe "#translate" do
 52 | 
 53 |   it "translates a word beginning with a vowel" do
 54 |     s = translate("apple")
 55 |     expect(s).to eq("appleay")
 56 |   end
 57 | 
 58 |   it "translates a word beginning with a consonant" do
 59 |     s = translate("banana")
 60 |     expect(s).to eq("ananabay")
 61 |   end
 62 | 
 63 |   it "translates a word beginning with two consonants" do
 64 |     s = translate("cherry")
 65 |     expect(s).to eq("errychay")
 66 |   end
 67 | 
 68 |   it "translates two words" do
 69 |     s = translate("eat pie")
 70 |     expect(s).to eq("eatay iepay")
 71 |   end
 72 | 
 73 |   it "translates a word beginning with three consonants" do
 74 |     expect(translate("three")).to eq("eethray")
 75 |   end
 76 | 
 77 |   it "counts 'sch' as a single phoneme" do
 78 |     s = translate("school")
 79 |     expect(s).to eq("oolschay")
 80 |   end
 81 | 
 82 |   it "counts 'qu' as a single phoneme" do
 83 |     s = translate("quiet")
 84 |     expect(s).to eq("ietquay")
 85 |   end
 86 | 
 87 |   it "counts 'qu' as a consonant even when it's preceded by a consonant" do
 88 |     s = translate("square")
 89 |     expect(s).to eq("aresquay")
 90 |   end
 91 | 
 92 |   it "translates many words" do
 93 |     s = translate("the quick brown fox")
 94 |     expect(s).to eq("ethay ickquay ownbray oxfay")
 95 |   end
 96 | 
 97 |   # Test-driving bonus:
 98 |   # * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course)
 99 |   # * retain the punctuation from the original phrase
100 | 
101 | end
102 |
103 |
104 |
105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /04_pig_latin/pig_latin.rb: -------------------------------------------------------------------------------- 1 | #write your code here 2 | -------------------------------------------------------------------------------- /04_pig_latin/pig_latin_spec.rb: -------------------------------------------------------------------------------- 1 | # # Topics 2 | # 3 | # * modules 4 | # * strings 5 | # 6 | # # Pig Latin 7 | # 8 | # Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand. 9 | # 10 | # Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. 11 | # 12 | # Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word. 13 | # 14 | # (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.) 15 | # 16 | # See for more details. 17 | # 18 | # 19 | 20 | require "pig_latin" 21 | 22 | describe "#translate" do 23 | 24 | it "translates a word beginning with a vowel" do 25 | s = translate("apple") 26 | expect(s).to eq("appleay") 27 | end 28 | 29 | it "translates a word beginning with a consonant" do 30 | s = translate("banana") 31 | expect(s).to eq("ananabay") 32 | end 33 | 34 | it "translates a word beginning with two consonants" do 35 | s = translate("cherry") 36 | expect(s).to eq("errychay") 37 | end 38 | 39 | it "translates two words" do 40 | s = translate("eat pie") 41 | expect(s).to eq("eatay iepay") 42 | end 43 | 44 | it "translates a word beginning with three consonants" do 45 | expect(translate("three")).to eq("eethray") 46 | end 47 | 48 | it "counts 'sch' as a single phoneme" do 49 | s = translate("school") 50 | expect(s).to eq("oolschay") 51 | end 52 | 53 | it "counts 'qu' as a single phoneme" do 54 | s = translate("quiet") 55 | expect(s).to eq("ietquay") 56 | end 57 | 58 | it "counts 'qu' as a consonant even when it's preceded by a consonant" do 59 | s = translate("square") 60 | expect(s).to eq("aresquay") 61 | end 62 | 63 | it "translates many words" do 64 | s = translate("the quick brown fox") 65 | expect(s).to eq("ethay ickquay ownbray oxfay") 66 | end 67 | 68 | # Test-driving bonus: 69 | # * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course) 70 | # * retain the punctuation from the original phrase 71 | 72 | end 73 | -------------------------------------------------------------------------------- /05_book_titles/book.rb: -------------------------------------------------------------------------------- 1 | class Book 2 | # write your code here 3 | end 4 | -------------------------------------------------------------------------------- /05_book_titles/book_titles_spec.rb: -------------------------------------------------------------------------------- 1 | # # Book Titles 2 | # 3 | # # Topics 4 | # 5 | # * classes and objects 6 | # * instance variables 7 | # * setter methods 8 | # * strings 9 | # 10 | # # Notes 11 | # 12 | # Book Titles in English obey some strange capitalization rules. For example, "and" is lowercase in "War and Peace". This test attempts to make sense of some of those rules. 13 | # 14 | 15 | require 'book' 16 | 17 | describe Book do 18 | 19 | before do 20 | @book = Book.new 21 | end 22 | 23 | describe 'title' do 24 | it 'should capitalize the first letter' do 25 | @book.title = "inferno" 26 | expect(@book.title).to eq("Inferno") 27 | end 28 | 29 | it 'should capitalize every word' do 30 | @book.title = "stuart little" 31 | expect(@book.title).to eq("Stuart Little") 32 | end 33 | 34 | describe 'should capitalize every word except...' do 35 | describe 'articles' do 36 | specify 'the' do 37 | @book.title = "alexander the great" 38 | expect(@book.title).to eq("Alexander the Great") 39 | end 40 | 41 | specify 'a' do 42 | @book.title = "to kill a mockingbird" 43 | expect(@book.title).to eq("To Kill a Mockingbird") 44 | end 45 | 46 | specify 'an' do 47 | @book.title = "to eat an apple a day" 48 | expect(@book.title).to eq("To Eat an Apple a Day") 49 | end 50 | end 51 | 52 | specify 'conjunctions' do 53 | @book.title = "war and peace" 54 | expect(@book.title).to eq("War and Peace") 55 | end 56 | 57 | specify 'prepositions' do 58 | @book.title = "love in the time of cholera" 59 | expect(@book.title).to eq("Love in the Time of Cholera") 60 | end 61 | end 62 | 63 | describe 'should always capitalize...' do 64 | specify 'I' do 65 | @book.title = "what i wish i knew when i was 20" 66 | expect(@book.title).to eq("What I Wish I Knew When I Was 20") 67 | end 68 | 69 | specify 'the first word' do 70 | @book.title = "the man in the iron mask" 71 | expect(@book.title).to eq("The Man in the Iron Mask") 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /05_book_titles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: book_titles 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

book_titles

25 |

Book Titles

26 | 27 |

Topics

28 | 29 |
    30 |
  • classes and objects
  • 31 |
  • instance variables
  • 32 |
  • setter methods
  • 33 |
  • strings
  • 34 |
35 | 36 | 37 |

Notes

38 | 39 |

Book Titles in English obey some strange capitalization rules. For example, "and" is lowercase in "War and Peace". This test attempts to make sense of some of those rules.

40 |
41 |
42 |

Tests

43 | book_titles_spec.rb 44 |
 45 | require 'book'
 46 | 
 47 | describe Book do
 48 | 
 49 |   before do
 50 |     @book = Book.new
 51 |   end
 52 | 
 53 |   describe 'title' do
 54 |     it 'should capitalize the first letter' do
 55 |       @book.title = "inferno"
 56 |       expect(@book.title).to eq("Inferno")
 57 |     end
 58 | 
 59 |     it 'should capitalize every word' do
 60 |       @book.title = "stuart little"
 61 |       expect(@book.title).to eq("Stuart Little")
 62 |     end
 63 | 
 64 |     describe 'should capitalize every word except...' do
 65 |       describe 'articles' do
 66 |         specify 'the' do
 67 |           @book.title = "alexander the great"
 68 |           expect(@book.title).to eq("Alexander the Great")
 69 |         end
 70 | 
 71 |         specify 'a' do
 72 |           @book.title = "to kill a mockingbird"
 73 |           expect(@book.title).to eq("To Kill a Mockingbird")
 74 |         end
 75 | 
 76 |         specify 'an' do
 77 |           @book.title = "to eat an apple a day"
 78 |           expect(@book.title).to eq("To Eat an Apple a Day")
 79 |         end
 80 |       end
 81 | 
 82 |       specify 'conjunctions' do
 83 |         @book.title = "war and peace"
 84 |         expect(@book.title).to eq("War and Peace")
 85 |       end
 86 | 
 87 |       specify 'prepositions' do
 88 |         @book.title = "love in the time of cholera"
 89 |         expect(@book.title).to eq("Love in the Time of Cholera")
 90 |       end
 91 |     end
 92 | 
 93 |     describe 'should always capitalize...' do
 94 |       specify 'I' do
 95 |         @book.title = "what i wish i knew when i was 20"
 96 |         expect(@book.title).to eq("What I Wish I Knew When I Was 20")
 97 |       end
 98 | 
 99 |       specify 'the first word' do
100 |         @book.title = "the man in the iron mask"
101 |         expect(@book.title).to eq("The Man in the Iron Mask")
102 |       end
103 |     end
104 |   end
105 | end
106 |
107 |
108 |
109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /06_timer/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test-First Teaching: learn_ruby: timer 4 | 5 | 6 | 7 |
8 |

TestFirst.org

9 |

the home of test-first teaching

10 |
11 | 24 |

timer

25 |

Topics

26 | 27 |
    28 |
  • classes
  • 29 |
  • instance variables
  • 30 |
  • string formats
  • 31 |
  • modular arithmetic
  • 32 |
33 | 34 | 35 |

Timer

36 |
37 |
38 |

Tests

39 | timer_spec.rb 40 |
41 | require 'timer'
42 | 
43 | describe "Timer" do
44 |   before(:each) do
45 |     @timer = Timer.new
46 |   end
47 | 
48 |   it "should initialize to 0 seconds" do
49 |     expect(@timer.seconds).to eq(0)
50 |   end
51 | 
52 |   describe 'time_string' do
53 |     it "should display 0 seconds as 00:00:00" do
54 |       @timer.seconds = 0
55 |       expect(@timer.time_string).to eq("00:00:00")
56 |     end
57 | 
58 |     it "should display 12 seconds as 00:00:12" do
59 |       @timer.seconds = 12
60 |       expect(@timer.time_string).to eq("00:00:12")
61 |     end
62 | 
63 |     it "should display 66 seconds as 00:01:06" do
64 |       @timer.seconds = 66
65 |       expect(@timer.time_string).to eq("00:01:06")
66 |     end
67 | 
68 |     it "should display 4000 seconds as 01:06:40" do
69 |       @timer.seconds = 4000
70 |       expect(@timer.time_string).to eq("01:06:40")
71 |     end
72 |   end
73 | 
74 | 
75 |   # One way to implement the Timer is with a helper method.
76 |   # Uncomment these specs if you want to test-drive that
77 |   # method, then call that method from inside of time_string.
78 |   #
79 |   # describe 'padded' do
80 |   #   it 'pads zero' do
81 |   #     expect(@timer.padded(0)).to eq('00')
82 |   #   end
83 |   #   it 'pads one' do
84 |   #     expect(@timer.padded(1)).to eq('01')
85 |   #   end
86 |   #   it "doesn't pad a two-digit number" do
87 |   #     expect(@timer.padded(12)).to eq('12')
88 |   #   end
89 |   # end
90 | 
91 | end
92 |
93 |
94 |
95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /06_timer/timer.rb: -------------------------------------------------------------------------------- 1 | class Timer 2 | #write your code here 3 | end 4 | -------------------------------------------------------------------------------- /06_timer/timer_spec.rb: -------------------------------------------------------------------------------- 1 | # # Topics 2 | # 3 | # * classes 4 | # * instance variables 5 | # * string formats 6 | # * modular arithmetic 7 | # 8 | # # Timer 9 | 10 | require 'timer' 11 | 12 | describe "Timer" do 13 | before(:each) do 14 | @timer = Timer.new 15 | end 16 | 17 | it "should initialize to 0 seconds" do 18 | expect(@timer.seconds).to eq(0) 19 | end 20 | 21 | describe 'time_string' do 22 | it "should display 0 seconds as 00:00:00" do 23 | @timer.seconds = 0 24 | expect(@timer.time_string).to eq("00:00:00") 25 | end 26 | 27 | it "should display 12 seconds as 00:00:12" do 28 | @timer.seconds = 12 29 | expect(@timer.time_string).to eq("00:00:12") 30 | end 31 | 32 | it "should display 66 seconds as 00:01:06" do 33 | @timer.seconds = 66 34 | expect(@timer.time_string).to eq("00:01:06") 35 | end 36 | 37 | it "should display 4000 seconds as 01:06:40" do 38 | @timer.seconds = 4000 39 | expect(@timer.time_string).to eq("01:06:40") 40 | end 41 | end 42 | 43 | 44 | # One way to implement the Timer is with a helper method. 45 | # Uncomment these specs if you want to test-drive that 46 | # method, then call that method from inside of time_string. 47 | # 48 | # describe 'padded' do 49 | # it 'pads zero' do 50 | # expect(@timer.padded(0)).to eq('00') 51 | # end 52 | # it 'pads one' do 53 | # expect(@timer.padded(1)).to eq('01') 54 | # end 55 | # it "doesn't pad a two-digit number" do 56 | # expect(@timer.padded(12)).to eq('12') 57 | # end 58 | # end 59 | 60 | end 61 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem 'rake', '~> 12.3' 4 | gem 'rspec', '~> 3.4' 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | diff-lcs (1.3) 5 | rake (10.5.0) 6 | rspec (3.5.0) 7 | rspec-core (~> 3.5.0) 8 | rspec-expectations (~> 3.5.0) 9 | rspec-mocks (~> 3.5.0) 10 | rspec-core (3.5.4) 11 | rspec-support (~> 3.5.0) 12 | rspec-expectations (3.5.0) 13 | diff-lcs (>= 1.2.0, < 2.0) 14 | rspec-support (~> 3.5.0) 15 | rspec-mocks (3.5.0) 16 | diff-lcs (>= 1.2.0, < 2.0) 17 | rspec-support (~> 3.5.0) 18 | rspec-support (3.5.0) 19 | 20 | PLATFORMS 21 | ruby 22 | 23 | DEPENDENCIES 24 | rake (< 11.0) 25 | rspec (~> 3.4) 26 | 27 | BUNDLED WITH 28 | 1.13.6 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Test First Ruby -- RSpec 3 Edition 2 | ========== 3 | 4 | ### Set up instructions 5 | 6 | 1. Fork this repo 7 | 2. Clone your version of the repo to your local machine 8 | 3. On your local machine, `cd` into the root folder of this repo in your terminal 9 | 4. run `bundle install` to install all the gems this project needs. 10 | 11 | ### Getting started with the exercises 12 | 13 | To work through the first exercise, follow this process 14 | 15 | 1. `cd` into `00_hello` from the root folder of this project 16 | 2. Run `rake`, to run the tests. It will fail with the following error: 17 | ``` 18 | Failures: 19 | 20 | 1) the hello function says hello 21 | Failure/Error: expect(hello).to eq("Hello!") 22 | 23 | NameError: 24 | undefined local variable or method `hello' for # 25 | # ./00_hello/hello_spec.rb:106:in `block (2 levels) in ' 26 | ``` 27 | 3. If the test fails to run and you get a `rake aborted! No Rakefile found` or any other error message not like the one above ensure that your working directory (`pwd` to see the path) contains no spaces as this is a common mistake made by people new to Rspec. 28 | 3. Read the failure output carefully and write the code that will make it pass 29 | 4. Run the tests again with `rake` 30 | 5. This will output that one test has passed and another test failure, write the code to make the next test pass. 31 | 4. Continue this process until all tests pass (when they are green) you have now completed the exercise. 32 | 5. Do this for all the exercises in this project 33 | 5. To get hints and tips about each exercise, view the `index.html` file that is included in each exercise folder 34 | 35 | 36 | Basically, this is "error-driven development"... you'll keep running tests, hitting error messages, fixing those messages, running more tests... It is meant to not only test your Ruby skills but also get you comfortable seeing big scary looking stack traces and error messages. Most of the development you do at first will be just like this. In fact, most of *all* development is error-driven. So get comfortable with it! 37 | 38 | ### Troubleshooting 39 | 40 | * Don't name any of your directories with spaces in them! It will give you horribly frustrating error messages and code hates dealing with spaces. For instance: 41 | 42 | ```language-bash 43 | # BAD: 44 | /Documents/My Homework/ruby 45 | 46 | # GOOD: 47 | /Documents/my_homework/ruby 48 | ``` 49 | 50 | 51 | ### Credit 52 | 53 | This is forked from [https://github.com/alexch/learn_ruby](https://github.com/alexch/learn_ruby), its original creator. 54 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # This Rakefile has all the right settings to run the tests inside each lab 2 | 3 | require 'rspec/core/rake_task' 4 | 5 | task :default => :spec 6 | 7 | desc "run tests for this lab" 8 | RSpec::Core::RakeTask.new do |task| 9 | lab = Rake.application.original_dir 10 | task.pattern = "#{lab}/*_spec.rb" 11 | task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f documentation', '-r ./rspec_config'] 12 | task.verbose = false 13 | end 14 | -------------------------------------------------------------------------------- /assets/style.css: -------------------------------------------------------------------------------- 1 | /* Solarized Palette http://ethanschoonover.com/solarized */ 2 | /* Font Stacks http://www.artsiteframework.com/guide/fontstacks.php */ 3 | body { 4 | background-color: white; 5 | font-family: Optima, Candara, "Trebuchet MS", sans-serif; 6 | margin: 0px; 7 | font-size: 15px; 8 | line-height: 19px; } 9 | 10 | a, a:visited { 11 | color: #268bd2; } 12 | 13 | a:hover { 14 | text-decoration: underline; } 15 | 16 | a { 17 | text-decoration: none; } 18 | 19 | .content { 20 | padding: 0 2em 0 18em; 21 | min-height: 30em; 22 | min-width: 20em; 23 | max-width: 44em; 24 | margin: 1em auto; } 25 | .content h1, .content h2, .content h3 { 26 | font-family: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif; 27 | margin-left: -1em; } 28 | .content h1 { 29 | text-shadow: #999 1px 1px 1px; 30 | padding: .5em .25em; 31 | margin-top: 1em; } 32 | .content h2 { 33 | margin-top: 1em; 34 | border-bottom: #268bd2 1px dotted; } 35 | .content pre { 36 | overflow-x: auto; } 37 | 38 | .header, .footer { 39 | font-size: 80%; 40 | padding: .25em; 41 | background-color: #f2f2f2; } 42 | 43 | .header { 44 | border-bottom: 1px solid #002b36; 45 | text-align: left; } 46 | .header h1 { 47 | color: #800000; 48 | margin: 0 0 -8px 0; 49 | padding: 0; 50 | font: 30px/48px Optima, Candara, "Trebuchet MS", sans-serif; 51 | letter-spacing: 0; } 52 | .header h2 { 53 | margin: 0 0 4px 13px; 54 | padding: 0; 55 | font: 10pt Optima, Candara, "Trebuchet MS", sans-serif; 56 | color: #686868; 57 | letter-spacing: 0; 58 | font-variant: small-caps; } 59 | .header a, .header a:visited { 60 | color: #800000; 61 | text-decoration: none; } 62 | .header a:hover { 63 | color: #37030B; 64 | text-decoration: none; } 65 | 66 | .footer { 67 | border-top: 1px solid #002b36; 68 | text-align: center; } 69 | 70 | .nav { 71 | float: left; 72 | margin: 1em; 73 | padding: 0 1em 1em; 74 | width: 14em; 75 | font-size: 75%; } 76 | 77 | .nav { 78 | background: -webkit-gradient(linear, left bottom, left top, color-stop(0.15, white), color-stop(0.85, #f2f2f2)); 79 | background: -moz-linear-gradient(center bottom, white 15%, #f2f2f2 85%); 80 | -moz-border-radius: 10px; 81 | border-radius: 10px; 82 | border: 1px solid black; } 83 | 84 | .rspec_file > .tests { 85 | position: relative; } 86 | .rspec_file > .tests a.raw_file { 87 | float: right; 88 | position: absolute; 89 | right: 0; 90 | padding: 2px 4px; 91 | margin: 3px; 92 | border: 1px solid #666; 93 | background: #ddd; } 94 | 95 | pre { 96 | font-family: "Lucida Sans Typewriter Regular", "lucida console", monaco, "andale mono", "bitstream vera sans mono", consolas, "DejaVu Sans Mono", Courier, "Courier New", monospace; 97 | background-color: #e9e9ff; 98 | padding: .5em 1em; 99 | border: 1px solid #93a1a1; } 100 | 101 | code { 102 | font-family: "Lucida Sans Typewriter Regular", "lucida console", monaco, "andale mono", "bitstream vera sans mono", consolas, "DejaVu Sans Mono", Courier, "Courier New", monospace; 103 | background-color: #efefff; } 104 | 105 | pre > code { 106 | background-color: #e9e9ff; } 107 | 108 | li > p:nth-child(0) { 109 | margin: 0; } 110 | 111 | ul li ul li { 112 | margin-top: .1em; 113 | margin-bottom: 1em; } 114 | -------------------------------------------------------------------------------- /rspec_config.rb: -------------------------------------------------------------------------------- 1 | RSpec.configure do |c| 2 | c.fail_fast = true 3 | c.color = true 4 | end 5 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rspec --init` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause this 4 | # file to always be loaded, without a need to explicitly require it in any files. 5 | # 6 | # Given that it is always loaded, you are encouraged to keep this file as 7 | # light-weight as possible. Requiring heavyweight dependencies from this file 8 | # will add to the boot time of your test suite on EVERY test run, even for an 9 | # individual file that may not need all of that loaded. Instead, consider making 10 | # a separate helper file that requires the additional dependencies and performs 11 | # the additional setup, and require it from the spec files that actually need it. 12 | # 13 | # The `.rspec` file also contains a few flags that are not defaults but that 14 | # users commonly want. 15 | # 16 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 17 | RSpec.configure do |config| 18 | # rspec-expectations config goes here. You can use an alternate 19 | # assertion/expectation library such as wrong or the stdlib/minitest 20 | # assertions if you prefer. 21 | config.expect_with :rspec do |expectations| 22 | # This option will default to `true` in RSpec 4. It makes the `description` 23 | # and `failure_message` of custom matchers include text for helper methods 24 | # defined using `chain`, e.g.: 25 | # be_bigger_than(2).and_smaller_than(4).description 26 | # # => "be bigger than 2 and smaller than 4" 27 | # ...rather than: 28 | # # => "be bigger than 2" 29 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 30 | end 31 | 32 | # rspec-mocks config goes here. You can use an alternate test double 33 | # library (such as bogus or mocha) by changing the `mock_with` option here. 34 | config.mock_with :rspec do |mocks| 35 | # Prevents you from mocking or stubbing a method that does not exist on 36 | # a real object. This is generally recommended, and will default to 37 | # `true` in RSpec 4. 38 | mocks.verify_partial_doubles = true 39 | end 40 | 41 | # The settings below are suggested to provide a good initial experience 42 | # with RSpec, but feel free to customize to your heart's content. 43 | =begin 44 | # These two settings work together to allow you to limit a spec run 45 | # to individual examples or groups you care about by tagging them with 46 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 47 | # get run. 48 | config.filter_run :focus 49 | config.run_all_when_everything_filtered = true 50 | 51 | # Limits the available syntax to the non-monkey patched syntax that is recommended. 52 | # For more details, see: 53 | # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax 54 | # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 55 | # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching 56 | config.disable_monkey_patching! 57 | 58 | # This setting enables warnings. It's recommended, but in some cases may 59 | # be too noisy due to issues in dependencies. 60 | config.warnings = true 61 | 62 | # Many RSpec users commonly either run the entire suite or an individual 63 | # file, and it's useful to allow more verbose output when running an 64 | # individual spec file. 65 | if config.files_to_run.one? 66 | # Use the documentation formatter for detailed output, 67 | # unless a formatter has already been configured 68 | # (e.g. via a command-line flag). 69 | config.default_formatter = 'doc' 70 | end 71 | 72 | # Print the 10 slowest examples and example groups at the 73 | # end of the spec run, to help surface which specs are running 74 | # particularly slow. 75 | config.profile_examples = 10 76 | 77 | # Run specs in random order to surface order dependencies. If you find an 78 | # order dependency and want to debug it, you can fix the order by providing 79 | # the seed, which is printed after each run. 80 | # --seed 1234 81 | config.order = :random 82 | 83 | # Seed global randomization in this process using the `--seed` CLI option. 84 | # Setting this allows you to use `--seed` to deterministically reproduce 85 | # test failures related to randomization by passing the same `--seed` value 86 | # as the one that triggered the failure. 87 | Kernel.srand config.seed 88 | =end 89 | end 90 | --------------------------------------------------------------------------------