Skip to content

Commit

Permalink
Merge pull request TheOdinProject#27 from strychemi/rspec-only
Browse files Browse the repository at this point in the history
Refactored RSpec syntax in HTML instructions
  • Loading branch information
eriktrautman committed Nov 16, 2015
2 parents 2d66244 + 3abb5d4 commit 0685d6c
Show file tree
Hide file tree
Showing 24 changed files with 234 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.idea

+.DS_Store*
12 changes: 6 additions & 6 deletions 00_hello/hello_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# You should see an error. **Don't get scared!** Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like
#
# no such file to load -- test-first-teaching/hello/hello (LoadError)
# cannot load such file -- test-first-teaching/hello/hello (LoadError)
#
# That means that it is looking for a file called `hello.rb` and can't find it.
#
Expand All @@ -36,7 +36,7 @@
# Failures:
#
# 1) the hello function says hello
# Failure/Error: hello.should == "Hello!"
# Failure/Error: expect(hello).to eq("Hello!")
# NameError:
# undefined local variable or method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808>
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
Expand All @@ -60,9 +60,9 @@
# Failures:
#
# 1) the hello function says hello
# Failure/Error: hello().should == "Hello!"
# Failure/Error: expect(hello).to eq("Hello!")
# expected: "Hello!"
# got: nil (using ==)
# got: nil (compared using ==)
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
#
# 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".)
Expand All @@ -82,9 +82,9 @@
# Now you should see an error like this:
#
# 1) the hello function says hello
# Failure/Error: hello().should == "Hello!"
# Failure/Error: expect(hello.to eq("Hello!")
# expected: "Hello!"
# got: "whuh?" (using ==)
# got: "whuh?" (compared using ==)
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
#
# Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.
Expand Down
18 changes: 9 additions & 9 deletions 00_hello/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h2>Watch it fail</h2>

<p>You should see an error. <strong>Don't get scared!</strong> Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like</p>

<pre><code>no such file to load -- test-first-teaching/hello/hello (LoadError)
<pre><code>cannot load such file -- test-first-teaching/hello/hello (LoadError)
</code></pre>

<p>That means that it is looking for a file called <code>hello.rb</code> and can't find it.</p>
Expand All @@ -73,7 +73,7 @@ <h2>Watch it fail</h2>
Failures:

1) the hello function says hello
Failure/Error: hello.should == "Hello!"
Failure/Error: expect(hello).to eq("Hello!")
NameError:
undefined local variable or method `hello' for #&lt;RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808&gt;
# ./hello/hello_spec.rb:5:in `block (2 levels) in &lt;top (required)&gt;'
Expand All @@ -99,9 +99,9 @@ <h2>Watch it fail</h2>
Failures:

1) the hello function says hello
Failure/Error: hello().should == "Hello!"
Failure/Error: expect(hello).to eq("Hello!")
expected: "Hello!"
got: nil (using ==)
got: nil (compared using ==)
# ./hello/hello_spec.rb:5:in `block (2 levels) in &lt;top (required)&gt;'
</code></pre>

Expand All @@ -123,9 +123,9 @@ <h2>Watch it fail</h2>
<p>Now you should see an error like this:</p>

<pre><code>1) the hello function says hello
Failure/Error: hello().should == "Hello!"
Failure/Error: expect(hello).to eq("Hello!")
expected: "Hello!"
got: "whuh?" (using ==)
got: "whuh?" (compared using ==)
# ./hello/hello_spec.rb:5:in `block (2 levels) in &lt;top (required)&gt;'
</code></pre>

Expand Down Expand Up @@ -164,17 +164,17 @@ <h1>Tests</h1>

describe &quot;the hello function&quot; do
it &quot;says hello&quot; do
hello.should == &quot;Hello!&quot;
expect(hello).to eq(&quot;Hello!&quot;)
end
end

describe &quot;the greet function&quot; do
it &quot;says hello to someone&quot; do
greet(&quot;Alice&quot;).should == &quot;Hello, Alice!&quot;
expect(greet(&quot;Alice&quot;)).to eq(&quot;Hello, Alice!&quot;)
end

it &quot;says hello to someone else&quot; do
greet(&quot;Bob&quot;).should == &quot;Hello, Bob!&quot;
expect(greet(&quot;Bob&quot;)).to eq(&quot;Hello, Bob!&quot;)
end
end</pre>
</div>
Expand Down
16 changes: 8 additions & 8 deletions 01_temperature/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,39 @@ <h1>Tests</h1>
describe &quot;#ftoc&quot; do

it &quot;converts freezing temperature&quot; do
ftoc(32).should == 0
expect(ftoc(32)).to eq(0)
end

it &quot;converts boiling temperature&quot; do
ftoc(212).should == 100
expect(ftoc(212)).to eq(100)
end

it &quot;converts body temperature&quot; do
ftoc(98.6).should == 37
expect(ftoc(98.6)).to eq(37)
end

it &quot;converts arbitrary temperature&quot; do
ftoc(68).should == 20
expect(ftoc(68)).to eq(20)
end

end

describe &quot;#ctof&quot; do

it &quot;converts freezing temperature&quot; do
ctof(0).should == 32
expect(ctof(0)).to eq(32)
end

it &quot;converts boiling temperature&quot; do
ctof(100).should == 212
expect(ctof(100)).to eq(212)
end

it &quot;converts arbitrary temperature&quot; do
ctof(20).should == 68
expect(ctof(20)).to eq(68)
end

it &quot;converts body temperature&quot; do
ctof(37).should be_within(0.1).of(98.6)
expect(ctof(37)).to be_within(0.1).of(98.6)
# Why do we need to use be_within?
# See http://www.ruby-forum.com/topic/169330
# and http://en.wikipedia.org/wiki/IEEE_754-2008
Expand Down
38 changes: 10 additions & 28 deletions 02_calculator/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,40 +78,22 @@
# write tests and code for the following:

describe "#multiply" do
it "multiplies two numbers" do
expect(multiply([1,2])).to eq(2)
end

it "multiplies several numbers" do
expect(multiply([1,2,3,4])).to eq(24)
end
it "multiplies two numbers"

it "multiplies several numbers"

end

describe "#power" do
it "raises one number to the power of another number" do
expect(power([2,4])).to eq(16)
end
it "raises one number to the power of another number"
end

# http://en.wikipedia.org/wiki/Factorial
describe "#factorial" do
it "computes the factorial of 0" do
expect(factorial(0)).to eq(1)
end

it "computes the factorial of 1" do
expect(factorial(1)).to eq(1)
end

it "computes the factorial of 2" do
expect(factorial(2)).to eq(2)
end

it "computes the factorial of 5" do
expect(factorial(5)).to eq(120)
end

it "computes the factorial of 10" do
expect(factorial(10)).to eq(3628800)
end
it "computes the factorial of 0"
it "computes the factorial of 1"
it "computes the factorial of 2"
it "computes the factorial of 5"
it "computes the factorial of 10"
end
16 changes: 8 additions & 8 deletions 02_calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,39 @@ <h1>Tests</h1>

describe &quot;add&quot; do
it &quot;adds 0 and 0&quot; do
add(0,0).should == 0
expect(add(0,0)).to eq(0)
end

it &quot;adds 2 and 2&quot; do
add(2,2).should == 4
expect(add(2,2)).to eq(4)
end

it &quot;adds positive numbers&quot; do
add(2,6).should == 8
expect(add(2,6)).to eq(8)
end
end

describe &quot;subtract&quot; do
it &quot;subtracts numbers&quot; do
subtract(10,4).should == 6
expect(subtract(10,4)).to eq(6)
end
end

describe &quot;sum&quot; do
it &quot;computes the sum of an empty array&quot; do
sum([]).should == 0
expect(sum([])).to eq(0)
end

it &quot;computes the sum of an array of one number&quot; do
sum([7]).should == 7
expect(sum([7])).to eq(7)
end

it &quot;computes the sum of an array of two numbers&quot; do
sum([7,11]).should == 18
expect(sum([7,11])).to eq(18)
end

it &quot;computes the sum of an array of many numbers&quot; do
sum([1,3,5,7,9]).should == 25
expect(sum([1,3,5,7,9])).to eq(25)
end
end

Expand Down
34 changes: 17 additions & 17 deletions 03_simon_says/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,80 +55,80 @@ <h1>Tests</h1>
describe &quot;Simon says&quot; do
describe &quot;echo&quot; do
it &quot;should echo hello&quot; do
echo(&quot;hello&quot;).should == &quot;hello&quot;
expect(echo(&quot;hello&quot;)).to eq(&quot;hello&quot;)
end

it &quot;should echo bye&quot; do
echo(&quot;bye&quot;).should == &quot;bye&quot;
expect(echo(&quot;bye&quot;)).to eq(&quot;bye&quot;)
end
end

describe &quot;shout&quot; do
it &quot;should shout hello&quot; do
shout(&quot;hello&quot;).should == &quot;HELLO&quot;
expect(shout(&quot;hello&quot;)).to eq(&quot;HELLO&quot;)
end

it &quot;should shout multiple words&quot; do
shout(&quot;hello world&quot;).should == &quot;HELLO WORLD&quot;
expect(shout(&quot;hello world&quot;)).to eq(&quot;HELLO WORLD&quot;)
end
end

describe &quot;repeat&quot; do
it &quot;should repeat&quot; do
repeat(&quot;hello&quot;).should == &quot;hello hello&quot;
expect(repeat(&quot;hello&quot;)).to eq(&quot;hello hello&quot;)
end

# Wait a second! How can you make the &quot;repeat&quot; method
# take one *or* two arguments?
#
# Hint: *default values*
it &quot;should repeat a number of times&quot; do
repeat(&quot;hello&quot;, 3).should == &quot;hello hello hello&quot;
expect(repeat(&quot;hello&quot;, 3)).to eq(&quot;hello hello hello&quot;)
end
end

describe &quot;start_of_word&quot; do
it &quot;returns the first letter&quot; do
start_of_word(&quot;hello&quot;, 1).should == &quot;h&quot;
expect(start_of_word(&quot;hello&quot;, 1)).to eq(&quot;h&quot;)
end

it &quot;returns the first two letters&quot; do
start_of_word(&quot;Bob&quot;, 2).should == &quot;Bo&quot;
expect(start_of_word(&quot;Bob&quot;, 2)).to eq(&quot;Bo&quot;)
end

it &quot;returns the first several letters&quot; do
s = &quot;abcdefg&quot;
start_of_word(s, 1).should == &quot;a&quot;
start_of_word(s, 2).should == &quot;ab&quot;
start_of_word(s, 3).should == &quot;abc&quot;
expect(start_of_word(s, 1)).to eq(&quot;a&quot;)
expect(start_of_word(s, 2)).to eq(&quot;ab&quot;)
expect(start_of_word(s, 3)).to eq(&quot;abc&quot;)
end
end

describe &quot;first_word&quot; do
it &quot;tells us the first word of 'Hello World' is 'Hello'&quot; do
first_word(&quot;Hello World&quot;).should == &quot;Hello&quot;
expect(first_word(&quot;Hello World&quot;)).to eq(&quot;Hello&quot;)
end

it &quot;tells us the first word of 'oh dear' is 'oh'&quot; do
first_word(&quot;oh dear&quot;).should == &quot;oh&quot;
expect(first_word(&quot;oh dear&quot;)).to eq(&quot;oh&quot;)
end
end

describe &quot;titleize&quot; do
it &quot;capitalizes a word&quot; do
titleize(&quot;jaws&quot;).should == &quot;Jaws&quot;
expect(titleize(&quot;jaws&quot;)).to eq(&quot;Jaws&quot;)
end

it &quot;capitalizes every word (aka title case)&quot; do
titleize(&quot;david copperfield&quot;).should == &quot;David Copperfield&quot;
expect(titleize(&quot;david copperfield&quot;)).to eq(&quot;David Copperfield&quot;)
end

it &quot;doesn't capitalize 'little words' in a title&quot; do
titleize(&quot;war and peace&quot;).should == &quot;War and Peace&quot;
expect(titleize(&quot;war and peace&quot;)).to eq(&quot;War and Peace&quot;)
end

it &quot;does capitalize 'little words' at the start of a title&quot; do
titleize(&quot;the bridge over the river kwai&quot;).should == &quot;The Bridge over the River Kwai&quot;
expect(titleize(&quot;the bridge over the river kwai&quot;)).to eq(&quot;The Bridge over the River Kwai&quot;)
end
end

Expand Down
Loading

0 comments on commit 0685d6c

Please sign in to comment.