Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring textual representation of specs #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions spec/00_hello_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,20 @@

require "00_hello"

describe "the hello function" do
it "says hello" do
expect(hello).to eq("Hello!")
describe "Hello" do
describe "#hello" do
it "says hello" do
expect(hello).to eq("Hello!")
end
end
end

describe "the greet function" do
it "says hello to someone" do
expect(greet("Alice")).to eq("Hello, Alice!")
end
describe "#greet" do
it "says hello to someone" do
expect(greet("Alice")).to eq("Hello, Alice!")
end

it "says hello to someone else" do
expect(greet("Bob")).to eq("Hello, Bob!")
it "says hello to someone else" do
expect(greet("Bob")).to eq("Hello, Bob!")
end
end
end
2 changes: 1 addition & 1 deletion spec/01_temperature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require "01_temperature"

describe "temperature conversion functions" do
describe "Temperature" do
describe "#ftoc" do
it "converts freezing temperature" do
expect(ftoc(32)).to eq(0)
Expand Down
90 changes: 46 additions & 44 deletions spec/02_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,62 +37,64 @@

require "02_calculator"

describe "add" do
it "adds 0 and 0" do
expect(add(0, 0)).to eq(0)
end
describe "Calculator" do
describe "#add" do
it "adds 0 and 0" do
expect(add(0, 0)).to eq(0)
end

it "adds 2 and 2" do
expect(add(2, 2)).to eq(4)
end
it "adds 2 and 2" do
expect(add(2, 2)).to eq(4)
end

it "adds positive numbers" do
expect(add(2, 6)).to eq(8)
it "adds positive numbers" do
expect(add(2, 6)).to eq(8)
end
end
end

describe "subtract" do
it "subtracts numbers" do
expect(subtract(10, 4)).to eq(6)
describe "#subtract" do
it "subtracts numbers" do
expect(subtract(10, 4)).to eq(6)
end
end
end

describe "sum" do
it "computes the sum of an empty array" do
expect(sum([])).to eq(0)
end
describe "#sum" do
it "computes the sum of an empty array" do
expect(sum([])).to eq(0)
end

it "computes the sum of an array of one number" do
expect(sum([7])).to eq(7)
end
it "computes the sum of an array of one number" do
expect(sum([7])).to eq(7)
end

it "computes the sum of an array of two numbers" do
expect(sum([7, 11])).to eq(18)
end
it "computes the sum of an array of two numbers" do
expect(sum([7, 11])).to eq(18)
end

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

# Extra Credit Test-Driving Bonus:
# once the above tests pass,
# write tests and code for the following:
# Extra Credit Test-Driving Bonus:
# once the above tests pass,
# write tests and code for the following:

describe "#multiply" do
it "multiplies two numbers"
it "multiplies several numbers"
end
describe "#multiply" do
it "multiplies two numbers"
it "multiplies several numbers"
end

describe "#power" do
it "raises one number to the power of another number"
end
describe "#power" do
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"
it "computes the factorial of 1"
it "computes the factorial of 2"
it "computes the factorial of 5"
it "computes the factorial of 10"
# http://en.wikipedia.org/wiki/Factorial
describe "#factorial" do
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
end
14 changes: 7 additions & 7 deletions spec/03_simon_says_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

require "03_simon_says"

describe "Simon says" do
describe "echo" do
describe "Simon Says" do
describe "#echo" do
it "should echo hello" do
expect(echo("hello")).to eq("hello")
end
Expand All @@ -24,7 +24,7 @@
end
end

describe "shout" do
describe "#shout" do
it "should shout hello" do
expect(shout("hello")).to eq("HELLO")
end
Expand All @@ -34,7 +34,7 @@
end
end

describe "repeat" do
describe "#repeat" do
it "should repeat" do
expect(repeat("hello")).to eq("hello hello")
end
Expand All @@ -48,7 +48,7 @@
end
end

describe "start_of_word" do
describe "#start_of_word" do
it "returns the first letter" do
expect(start_of_word("hello", 1)).to eq("h")
end
Expand All @@ -65,7 +65,7 @@
end
end

describe "first_word" do
describe "#first_word" do
it "tells us the first word of 'Hello World' is 'Hello'" do
expect(first_word("Hello World")).to eq("Hello")
end
Expand All @@ -75,7 +75,7 @@
end
end

describe "titleize" do
describe "#titleize" do
it "capitalizes a word" do
expect(titleize("jaws")).to eq("Jaws")
end
Expand Down
80 changes: 41 additions & 39 deletions spec/04_pig_latin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,54 @@

require "04_pig_latin"

describe "#translate" do
it "translates a word beginning with a vowel" do
s = translate("apple")
expect(s).to eq("appleay")
end
describe "Pig Latin" do
describe "#translate" do
it "translates a word beginning with a vowel" do
s = translate("apple")
expect(s).to eq("appleay")
end

it "translates a word beginning with a consonant" do
s = translate("banana")
expect(s).to eq("ananabay")
end
it "translates a word beginning with a consonant" do
s = translate("banana")
expect(s).to eq("ananabay")
end

it "translates a word beginning with two consonants" do
s = translate("cherry")
expect(s).to eq("errychay")
end
it "translates a word beginning with two consonants" do
s = translate("cherry")
expect(s).to eq("errychay")
end

it "translates two words" do
s = translate("eat pie")
expect(s).to eq("eatay iepay")
end
it "translates two words" do
s = translate("eat pie")
expect(s).to eq("eatay iepay")
end

it "translates a word beginning with three consonants" do
expect(translate("three")).to eq("eethray")
end
it "translates a word beginning with three consonants" do
expect(translate("three")).to eq("eethray")
end

it "counts 'sch' as a single phoneme" do
s = translate("school")
expect(s).to eq("oolschay")
end
it "counts 'sch' as a single phoneme" do
s = translate("school")
expect(s).to eq("oolschay")
end

it "counts 'qu' as a single phoneme" do
s = translate("quiet")
expect(s).to eq("ietquay")
end
it "counts 'qu' as a single phoneme" do
s = translate("quiet")
expect(s).to eq("ietquay")
end

it "counts 'qu' as a consonant even when it's preceded by a consonant" do
s = translate("square")
expect(s).to eq("aresquay")
end
it "counts 'qu' as a consonant even when it's preceded by a consonant" do
s = translate("square")
expect(s).to eq("aresquay")
end

it "translates many words" do
s = translate("the quick brown fox")
expect(s).to eq("ethay ickquay ownbray oxfay")
end
it "translates many words" do
s = translate("the quick brown fox")
expect(s).to eq("ethay ickquay ownbray oxfay")
end

# Test-driving bonus:
# * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course)
# * retain the punctuation from the original phrase
# Test-driving bonus:
# * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course)
# * retain the punctuation from the original phrase
end
end
8 changes: 4 additions & 4 deletions spec/05_silly_blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

require "05_silly_blocks"

describe "some silly block functions" do
describe "reverser" do
describe "Silly Blocks" do
describe "#reverser" do
it "reverses the string returned by the default block" do
result = reverser do
"hello"
Expand All @@ -26,7 +26,7 @@
end
end

describe "adder" do
describe "#adder" do
it "adds one to the value returned by the default block" do
expect(adder { 5 }).to eq(6)
end
Expand All @@ -36,7 +36,7 @@
end
end

describe "repeater" do
describe "#repeater" do
it "executes the default block" do
block_was_executed = false

Expand Down
Loading