From 5f9f6467438dead0ca5a41d342e594fb1ae4be89 Mon Sep 17 00:00:00 2001 From: Shane Barringer Date: Tue, 20 Oct 2015 18:41:38 -0400 Subject: [PATCH 1/7] Updates Rspec syntax for 3.0 + --- 00_hello/hello_spec.rb | 6 +- 01_temperature/temperature_spec.rb | 16 ++-- 02_calculator/calculator_spec.rb | 16 ++-- 03_simon_says/simon_says_spec.rb | 34 +++---- 04_pig_latin/pig_latin_spec.rb | 18 ++-- 05_silly_blocks/silly_blocks_spec.rb | 18 ++-- .../performance_monitor_spec.rb | 22 ++--- 07_hello_friend/hello_friend_spec.rb | 4 +- 08_book_titles/book_titles_spec.rb | 18 ++-- 09_timer/timer_spec.rb | 10 +- .../temperature_object_spec.rb | 38 ++++---- 11_dictionary/dictionary_spec.rb | 32 +++---- 12_rpn_calculator/rpn_calculator_spec.rb | 35 ++++--- 13_xml_document/xml_document_spec.rb | 23 ++--- 14_array_extensions/array_extensions_spec.rb | 12 +-- 15_in_words/in_words_spec.rb | 94 +++++++++---------- Gemfile.lock | 28 ++++++ 17 files changed, 229 insertions(+), 195 deletions(-) create mode 100644 Gemfile.lock diff --git a/00_hello/hello_spec.rb b/00_hello/hello_spec.rb index 3ffd5cce4..ab64fc9c4 100644 --- a/00_hello/hello_spec.rb +++ b/00_hello/hello_spec.rb @@ -117,16 +117,16 @@ describe "the hello function" do it "says hello" do - hello.should == "Hello!" + expect(hello).to eq("Hello!") end end describe "the greet function" do it "says hello to someone" do - greet("Alice").should == "Hello, Alice!" + expect(greet("Alice")).to eq("Hello, Alice!") end it "says hello to someone else" do - greet("Bob").should == "Hello, Bob!" + expect(greet("Bob")).to eq("Hello, Bob!") end end diff --git a/01_temperature/temperature_spec.rb b/01_temperature/temperature_spec.rb index 6cad3701c..7e92a54dc 100644 --- a/01_temperature/temperature_spec.rb +++ b/01_temperature/temperature_spec.rb @@ -22,19 +22,19 @@ describe "#ftoc" do it "converts freezing temperature" do - ftoc(32).should == 0 + expect(ftoc(32)).to eq(0) end it "converts boiling temperature" do - ftoc(212).should == 100 + expect(ftoc(212)).to eq(100) end it "converts body temperature" do - ftoc(98.6).should == 37 + expect(ftoc(98.6)).to eq(37) end it "converts arbitrary temperature" do - ftoc(68).should == 20 + expect(ftoc(68)).to eq(20) end end @@ -42,19 +42,19 @@ describe "#ctof" do it "converts freezing temperature" do - ctof(0).should == 32 + expect(ctof(0)).to eq(32) end it "converts boiling temperature" do - ctof(100).should == 212 + expect(ctof(100)).to eq(212) end it "converts arbitrary temperature" do - ctof(20).should == 68 + expect(ctof(20)).to eq(68) end it "converts body temperature" 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 diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index 29c91f64e..f7017a930 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -37,39 +37,39 @@ describe "add" do it "adds 0 and 0" do - add(0,0).should == 0 + expect(add(0,0)).to eq(0) end it "adds 2 and 2" do - add(2,2).should == 4 + expect(add(2,2)).to eq(4) end it "adds positive numbers" do - add(2,6).should == 8 + expect(add(2,6)).to eq(8) end end describe "subtract" do it "subtracts numbers" do - subtract(10,4).should == 6 + expect(subtract(10,4)).to eq(6) end end describe "sum" do it "computes the sum of an empty array" do - sum([]).should == 0 + expect(sum([])).to eq(0) end it "computes the sum of an array of one number" do - sum([7]).should == 7 + expect(sum([7])).to eq(7) end it "computes the sum of an array of two numbers" do - sum([7,11]).should == 18 + expect(sum([7,11])).to eq(18) end it "computes the sum of an array of many numbers" do - sum([1,3,5,7,9]).should == 25 + expect(sum([1,3,5,7,9])).to eq(25) end end diff --git a/03_simon_says/simon_says_spec.rb b/03_simon_says/simon_says_spec.rb index 8dac0b9f0..2c62be76d 100644 --- a/03_simon_says/simon_says_spec.rb +++ b/03_simon_says/simon_says_spec.rb @@ -16,27 +16,27 @@ describe "Simon says" do describe "echo" do it "should echo hello" do - echo("hello").should == "hello" + expect(echo("hello")).to eq("hello") end it "should echo bye" do - echo("bye").should == "bye" + expect(echo("bye")).to eq("bye") end end describe "shout" do it "should shout hello" do - shout("hello").should == "HELLO" + expect(shout("hello")).to eq("HELLO") end it "should shout multiple words" do - shout("hello world").should == "HELLO WORLD" + expect(shout("hello world")).to eq("HELLO WORLD") end end describe "repeat" do it "should repeat" do - repeat("hello").should == "hello hello" + expect(repeat("hello")).to eq("hello hello") end # Wait a second! How can you make the "repeat" method @@ -44,52 +44,52 @@ # # Hint: *default values* it "should repeat a number of times" do - repeat("hello", 3).should == "hello hello hello" + expect(repeat("hello", 3)).to eq("hello hello hello") end end describe "start_of_word" do it "returns the first letter" do - start_of_word("hello", 1).should == "h" + expect(start_of_word("hello", 1)).to eq("h") end it "returns the first two letters" do - start_of_word("Bob", 2).should == "Bo" + expect(start_of_word("Bob", 2)).to eq("Bo") end it "returns the first several letters" do s = "abcdefg" - start_of_word(s, 1).should == "a" - start_of_word(s, 2).should == "ab" - start_of_word(s, 3).should == "abc" + expect(start_of_word(s, 1)).to eq("a") + expect(start_of_word(s, 2)).to eq("ab") + expect(start_of_word(s, 3)).to eq("abc") end end describe "first_word" do it "tells us the first word of 'Hello World' is 'Hello'" do - first_word("Hello World").should == "Hello" + expect(first_word("Hello World")).to eq("Hello") end it "tells us the first word of 'oh dear' is 'oh'" do - first_word("oh dear").should == "oh" + expect(first_word("oh dear")).to eq("oh") end end describe "titleize" do it "capitalizes a word" do - titleize("jaws").should == "Jaws" + expect(titleize("jaws")).to eq("Jaws") end it "capitalizes every word (aka title case)" do - titleize("david copperfield").should == "David Copperfield" + expect(titleize("david copperfield")).to eq("David Copperfield") end it "doesn't capitalize 'little words' in a title" do - titleize("war and peace").should == "War and Peace" + expect(titleize("war and peace")).to eq("War and Peace") end it "does capitalize 'little words' at the start of a title" do - titleize("the bridge over the river kwai").should == "The Bridge over the River Kwai" + expect(titleize("the bridge over the river kwai")).to eq("The Bridge over the River Kwai") end end diff --git a/04_pig_latin/pig_latin_spec.rb b/04_pig_latin/pig_latin_spec.rb index 86328f2a4..cc659edfd 100644 --- a/04_pig_latin/pig_latin_spec.rb +++ b/04_pig_latin/pig_latin_spec.rb @@ -23,46 +23,46 @@ it "translates a word beginning with a vowel" do s = translate("apple") - s.should == "appleay" + expect(s).to eq("appleay") end it "translates a word beginning with a consonant" do s = translate("banana") - s.should == "ananabay" + expect(s).to eq("ananabay") end it "translates a word beginning with two consonants" do s = translate("cherry") - s.should == "errychay" + expect(s).to eq("errychay") end it "translates two words" do s = translate("eat pie") - s.should == "eatay iepay" + expect(s).to eq("eatay iepay") end it "translates a word beginning with three consonants" do - translate("three").should == "eethray" + expect(translate("three")).to eq("eethray") end it "counts 'sch' as a single phoneme" do s = translate("school") - s.should == "oolschay" + expect(s).to eq("oolschay") end it "counts 'qu' as a single phoneme" do s = translate("quiet") - s.should == "ietquay" + expect(s).to eq("ietquay") end it "counts 'qu' as a consonant even when it's preceded by a consonant" do s = translate("square") - s.should == "aresquay" + expect(s).to eq("aresquay") end it "translates many words" do s = translate("the quick brown fox") - s.should == "ethay ickquay ownbray oxfay" + expect(s).to eq("ethay ickquay ownbray oxfay") end # Test-driving bonus: diff --git a/05_silly_blocks/silly_blocks_spec.rb b/05_silly_blocks/silly_blocks_spec.rb index 6a34b2cff..c64e3ef70 100644 --- a/05_silly_blocks/silly_blocks_spec.rb +++ b/05_silly_blocks/silly_blocks_spec.rb @@ -15,28 +15,28 @@ result = reverser do "hello" end - result.should == "olleh" + expect(result).to eq("olleh") end it "reverses each word in the string returned by the default block" do result = reverser do "hello dolly" end - result.should == "olleh yllod" + expect(result).to eq("olleh yllod") end end describe "adder" do it "adds one to the value returned by the default block" do - adder do + expect(adder do 5 - end.should == 6 + end).to eq(6) end it "adds 3 to the value returned by the default block" do - adder(3) do + expect(adder(3) do 5 - end.should == 8 + end).to eq(8) end end @@ -46,7 +46,7 @@ repeater do block_was_executed = true end - block_was_executed.should == true + expect(block_was_executed).to eq(true) end it "executes the default block 3 times" do @@ -54,7 +54,7 @@ repeater(3) do n += 1 end - n.should == 3 + expect(n).to eq(3) end it "executes the default block 10 times" do @@ -62,7 +62,7 @@ repeater(10) do n += 1 end - n.should == 10 + expect(n).to eq(10) end end diff --git a/06_performance_monitor/performance_monitor_spec.rb b/06_performance_monitor/performance_monitor_spec.rb index 04820d4f7..f447f39c6 100644 --- a/06_performance_monitor/performance_monitor_spec.rb +++ b/06_performance_monitor/performance_monitor_spec.rb @@ -20,30 +20,30 @@ it "takes about 0 seconds to run an empty block" do elapsed_time = measure do end - elapsed_time.should be_within(0.1).of(0) + expect(elapsed_time).to be_within(0.1).of(0) end it "takes exactly 0 seconds to run an empty block (with stubs)" do - Time.stub(:now) { @eleven_am } + allow(Time).to receive(:now) { @eleven_am } elapsed_time = measure do end - elapsed_time.should == 0 + expect(elapsed_time).to eq(0) end it "takes about 1 second to run a block that sleeps for 1 second" do elapsed_time = measure do sleep 1 end - elapsed_time.should be_within(0.1).of(1) + expect(elapsed_time).to be_within(0.1).of(1) end it "takes exactly 1 second to run a block that sleeps for 1 second (with stubs)" do fake_time = @eleven_am - Time.stub(:now) { fake_time } + allow(Time).to receive(:now) { fake_time } elapsed_time = measure do fake_time += 60 # adds one minute to fake_time end - elapsed_time.should == 60 + expect(elapsed_time).to eq(60) end it "runs a block N times" do @@ -51,28 +51,28 @@ measure(4) do n += 1 end - n.should == 4 + expect(n).to eq(4) end it "returns the average time, not the total time, when running multiple times" do run_times = [8,6,5,7] fake_time = @eleven_am - Time.stub(:now) { fake_time } + allow(Time).to receive(:now) { fake_time } average_time = measure(4) do fake_time += run_times.pop end - average_time.should == 6.5 + expect(average_time).to eq(6.5) end it "returns the average time when running a random number of times for random lengths of time" do fake_time = @eleven_am - Time.stub(:now) { fake_time } + allow(Time).to receive(:now) { fake_time } number_of_times = rand(10) + 2 average_time = measure(number_of_times) do delay = rand(10) fake_time += delay end - average_time.should == (fake_time - @eleven_am).to_f/number_of_times + expect(average_time).to eq((fake_time - @eleven_am).to_f/number_of_times) end end diff --git a/07_hello_friend/hello_friend_spec.rb b/07_hello_friend/hello_friend_spec.rb index 29b25730f..de5d4962f 100644 --- a/07_hello_friend/hello_friend_spec.rb +++ b/07_hello_friend/hello_friend_spec.rb @@ -92,10 +92,10 @@ describe Friend do it "says hello" do - Friend.new.greeting.should == "Hello!" + expect(Friend.new.greeting).to eq("Hello!") end it "says hello to someone" do - Friend.new.greeting("Bob").should == "Hello, Bob!" + expect(Friend.new.greeting("Bob")).to eq("Hello, Bob!") end end diff --git a/08_book_titles/book_titles_spec.rb b/08_book_titles/book_titles_spec.rb index d7bc9a359..72822c6b8 100644 --- a/08_book_titles/book_titles_spec.rb +++ b/08_book_titles/book_titles_spec.rb @@ -23,52 +23,52 @@ describe 'title' do it 'should capitalize the first letter' do @book.title = "inferno" - @book.title.should == "Inferno" + expect(@book.title).to eq("Inferno") end it 'should capitalize every word' do @book.title = "stuart little" - @book.title.should == "Stuart Little" + expect(@book.title).to eq("Stuart Little") end describe 'should capitalize every word except...' do describe 'articles' do specify 'the' do @book.title = "alexander the great" - @book.title.should == "Alexander the Great" + expect(@book.title).to eq("Alexander the Great") end specify 'a' do @book.title = "to kill a mockingbird" - @book.title.should == "To Kill a Mockingbird" + expect(@book.title).to eq("To Kill a Mockingbird") end specify 'an' do @book.title = "to eat an apple a day" - @book.title.should == "To Eat an Apple a Day" + expect(@book.title).to eq("To Eat an Apple a Day") end end specify 'conjunctions' do @book.title = "war and peace" - @book.title.should == "War and Peace" + expect(@book.title).to eq("War and Peace") end specify 'prepositions' do @book.title = "love in the time of cholera" - @book.title.should == "Love in the Time of Cholera" + expect(@book.title).to eq("Love in the Time of Cholera") end end describe 'should always capitalize...' do specify 'I' do @book.title = "what i wish i knew when i was 20" - @book.title.should == "What I Wish I Knew When I Was 20" + expect(@book.title).to eq("What I Wish I Knew When I Was 20") end specify 'the first word' do @book.title = "the man in the iron mask" - @book.title.should == "The Man in the Iron Mask" + expect(@book.title).to eq("The Man in the Iron Mask") end end end diff --git a/09_timer/timer_spec.rb b/09_timer/timer_spec.rb index d1baf90b3..c91421acf 100644 --- a/09_timer/timer_spec.rb +++ b/09_timer/timer_spec.rb @@ -15,28 +15,28 @@ end it "should initialize to 0 seconds" do - @timer.seconds.should == 0 + expect(@timer.seconds).to eq(0) end describe 'time_string' do it "should display 0 seconds as 00:00:00" do @timer.seconds = 0 - @timer.time_string.should == "00:00:00" + expect(@timer.time_string).to eq("00:00:00") end it "should display 12 seconds as 00:00:12" do @timer.seconds = 12 - @timer.time_string.should == "00:00:12" + expect(@timer.time_string).to eq("00:00:12") end it "should display 66 seconds as 00:01:06" do @timer.seconds = 66 - @timer.time_string.should == "00:01:06" + expect(@timer.time_string).to eq("00:01:06") end it "should display 4000 seconds as 01:06:40" do @timer.seconds = 4000 - @timer.time_string.should == "01:06:40" + expect(@timer.time_string).to eq("01:06:40") end end diff --git a/10_temperature_object/temperature_object_spec.rb b/10_temperature_object/temperature_object_spec.rb index fe21c1135..5c0af8685 100644 --- a/10_temperature_object/temperature_object_spec.rb +++ b/10_temperature_object/temperature_object_spec.rb @@ -24,44 +24,44 @@ describe "can be constructed with an options hash" do describe "in degrees fahrenheit" do it "at 50 degrees" do - Temperature.new(:f => 50).in_fahrenheit.should == 50 + expect(Temperature.new(:f => 50).in_fahrenheit).to eq(50) end describe "and correctly convert to celsius" do it "at freezing" do - Temperature.new(:f => 32).in_celsius.should == 0 + expect(Temperature.new(:f => 32).in_celsius).to eq(0) end it "at boiling" do - Temperature.new(:f => 212).in_celsius.should == 100 + expect(Temperature.new(:f => 212).in_celsius).to eq(100) end it "at body temperature" do - Temperature.new(:f => 98.6).in_celsius.should == 37 + expect(Temperature.new(:f => 98.6).in_celsius).to eq(37) end it "at an arbitrary temperature" do - Temperature.new(:f => 68).in_celsius.should == 20 + expect(Temperature.new(:f => 68).in_celsius).to eq(20) end end end describe "in degrees celsius" do it "at 50 degrees" do - Temperature.new(:c => 50).in_celsius.should == 50 + expect(Temperature.new(:c => 50).in_celsius).to eq(50) end describe "and correctly convert to fahrenheit" do it "at freezing" do - Temperature.new(:c => 0).in_fahrenheit.should == 32 + expect(Temperature.new(:c => 0).in_fahrenheit).to eq(32) end it "at boiling" do - Temperature.new(:c => 100).in_fahrenheit.should == 212 + expect(Temperature.new(:c => 100).in_fahrenheit).to eq(212) end it "at body temperature" do - Temperature.new(:c => 37).in_fahrenheit.should be_within(0.1).of(98.6) + expect(Temperature.new(:c => 37).in_fahrenheit).to be_within(0.1).of(98.6) # Why do we need to use be_within here? # See http://www.ruby-forum.com/topic/169330 # and http://groups.google.com/group/rspec/browse_thread/thread/f3ebbe3c313202bb @@ -78,13 +78,13 @@ describe "can be constructed via factory methods" do it "in degrees celsius" do - Temperature.from_celsius(50).in_celsius.should == 50 - Temperature.from_celsius(50).in_fahrenheit.should == 122 + expect(Temperature.from_celsius(50).in_celsius).to eq(50) + expect(Temperature.from_celsius(50).in_fahrenheit).to eq(122) end it "in degrees fahrenheit" do - Temperature.from_fahrenheit(50).in_fahrenheit.should == 50 - Temperature.from_fahrenheit(50).in_celsius.should == 10 + expect(Temperature.from_fahrenheit(50).in_fahrenheit).to eq(50) + expect(Temperature.from_fahrenheit(50).in_celsius).to eq(10) end end @@ -104,23 +104,23 @@ describe "Temperature subclasses" do describe "Celsius subclass" do it "is constructed in degrees celsius" do - Celsius.new(50).in_celsius.should == 50 - Celsius.new(50).in_fahrenheit.should == 122 + expect(Celsius.new(50).in_celsius).to eq(50) + expect(Celsius.new(50).in_fahrenheit).to eq(122) end it "is a Temperature subclass" do - Celsius.new(0).should be_a(Temperature) + expect(Celsius.new(0)).to be_a(Temperature) end end describe "Fahrenheit subclass" do it "is constructed in degrees fahrenheit" do - Fahrenheit.new(50).in_fahrenheit.should == 50 - Fahrenheit.new(50).in_celsius.should == 10 + expect(Fahrenheit.new(50).in_fahrenheit).to eq(50) + expect(Fahrenheit.new(50).in_celsius).to eq(10) end it "is a Temperature subclass" do - Fahrenheit.new(0).should be_a(Temperature) + expect(Fahrenheit.new(0)).to be_a(Temperature) end end end diff --git a/11_dictionary/dictionary_spec.rb b/11_dictionary/dictionary_spec.rb index 85f147ccf..48a1e570d 100644 --- a/11_dictionary/dictionary_spec.rb +++ b/11_dictionary/dictionary_spec.rb @@ -14,70 +14,70 @@ end it 'is empty when created' do - @d.entries.should == {} + expect(@d.entries).to eq({}) end it 'can add whole entries with keyword and definition' do @d.add('fish' => 'aquatic animal') - @d.entries.should == {'fish' => 'aquatic animal'} - @d.keywords.should == ['fish'] + expect(@d.entries).to eq({'fish' => 'aquatic animal'}) + expect(@d.keywords).to eq(['fish']) end it 'add keywords (without definition)' do @d.add('fish') - @d.entries.should == {'fish' => nil} - @d.keywords.should == ['fish'] + expect(@d.entries).to eq({'fish' => nil}) + expect(@d.keywords).to eq(['fish']) end it 'can check whether a given keyword exists' do - @d.include?('fish').should be_false + expect(@d.include?('fish')).to be_falsey end it "doesn't cheat when checking whether a given keyword exists" do - @d.include?('fish').should be_false # if the method is empty, this test passes with nil returned + expect(@d.include?('fish')).to be_falsey # if the method is empty, this test passes with nil returned @d.add('fish') - @d.include?('fish').should be_true # confirms that it actually checks - @d.include?('bird').should be_false # confirms not always returning true after add + expect(@d.include?('fish')).to be_truthy # confirms that it actually checks + expect(@d.include?('bird')).to be_falsey # confirms not always returning true after add end it "doesn't include a prefix that wasn't added as a word in and of itself" do @d.add('fish') - @d.include?('fi').should be_false + expect(@d.include?('fi')).to be_falsey end it "doesn't find a word in empty dictionary" do - @d.find('fi').should be_empty # {} + expect(@d.find('fi')).to be_empty # {} end it 'finds nothing if the prefix matches nothing' do @d.add('fiend') @d.add('great') - @d.find('nothing').should be_empty + expect(@d.find('nothing')).to be_empty end it "finds an entry" do @d.add('fish' => 'aquatic animal') - @d.find('fish').should == {'fish' => 'aquatic animal'} + expect(@d.find('fish')).to eq({'fish' => 'aquatic animal'}) end it 'finds multiple matches from a prefix and returns the entire entry (keyword + definition)' do @d.add('fish' => 'aquatic animal') @d.add('fiend' => 'wicked person') @d.add('great' => 'remarkable') - @d.find('fi').should == {'fish' => 'aquatic animal', 'fiend' => 'wicked person'} + expect(@d.find('fi')).to eq({'fish' => 'aquatic animal', 'fiend' => 'wicked person'}) end it 'lists keywords alphabetically' do @d.add('zebra' => 'African land animal with stripes') @d.add('fish' => 'aquatic animal') @d.add('apple' => 'fruit') - @d.keywords.should == %w(apple fish zebra) + expect(@d.keywords).to eq(%w(apple fish zebra)) end it 'can produce printable output like so: [keyword] "definition"' do @d.add('zebra' => 'African land animal with stripes') @d.add('fish' => 'aquatic animal') @d.add('apple' => 'fruit') - @d.printable.should == %Q{[apple] "fruit"\n[fish] "aquatic animal"\n[zebra] "African land animal with stripes"} + expect(@d.printable).to eq(%Q{[apple] "fruit"\n[fish] "aquatic animal"\n[zebra] "African land animal with stripes"}) end end diff --git a/12_rpn_calculator/rpn_calculator_spec.rb b/12_rpn_calculator/rpn_calculator_spec.rb index 0b57f136b..f6c65aa78 100644 --- a/12_rpn_calculator/rpn_calculator_spec.rb +++ b/12_rpn_calculator/rpn_calculator_spec.rb @@ -47,7 +47,7 @@ calculator.push(2) calculator.push(3) calculator.plus - calculator.value.should == 5 + expect(calculator.value).to eq(5) end it "adds three numbers" do @@ -55,16 +55,16 @@ calculator.push(3) calculator.push(4) calculator.plus - calculator.value.should == 7 + expect(calculator.value).to eq(7) calculator.plus - calculator.value.should == 9 + expect(calculator.value).to eq(9) end it "subtracts the second number from the first number" do calculator.push(2) calculator.push(3) calculator.minus - calculator.value.should == -1 + expect(calculator.value).to eq(-1) end it "adds and subtracts" do @@ -72,9 +72,9 @@ calculator.push(3) calculator.push(4) calculator.minus - calculator.value.should == -1 + expect(calculator.value).to eq(-1) calculator.plus - calculator.value.should == 1 + expect(calculator.value).to eq(1) end it "multiplies and divides" do @@ -82,9 +82,9 @@ calculator.push(3) calculator.push(4) calculator.divide - calculator.value.should == (3.0 / 4.0) + expect(calculator.value).to eq(3.0 / 4.0) calculator.times - calculator.value.should == 2.0 * (3.0 / 4.0) + expect(calculator.value).to eq(2.0 * (3.0 / 4.0)) end it "resolves operator precedence unambiguously" do @@ -94,7 +94,7 @@ calculator.plus calculator.push(3) calculator.times - calculator.value.should == (1+2)*3 + expect(calculator.value).to eq((1+2)*3) # 1 2 3 * + => 1 + (2 * 3) calculator.push(1) @@ -102,7 +102,7 @@ calculator.push(3) calculator.times calculator.plus - calculator.value.should == 1+(2*3) + expect(calculator.value).to eq(1+(2*3)) end it "fails informatively when there's not enough values stacked away" do @@ -125,23 +125,28 @@ # extra credit it "tokenizes a string" do - calculator.tokens("1 2 3 * + 4 5 - /").should == + expect(calculator.tokens("1 2 3 * + 4 5 - /")).to eq( [1, 2, 3, :*, :+, 4, 5, :-, :/] + ) end # extra credit it "evaluates a string" do - calculator.evaluate("1 2 3 * +").should == + expect(calculator.evaluate("1 2 3 * +")).to eq( ((2 * 3) + 1) + ) - calculator.evaluate("4 5 -").should == + expect(calculator.evaluate("4 5 -")).to eq( (4 - 5) + ) - calculator.evaluate("2 3 /").should == + expect(calculator.evaluate("2 3 /")).to eq( (2.0 / 3.0) + ) - calculator.evaluate("1 2 3 * + 4 5 - /").should == + expect(calculator.evaluate("1 2 3 * + 4 5 - /")).to eq( (1.0 + (2 * 3)) / (4 - 5) + ) end end diff --git a/13_xml_document/xml_document_spec.rb b/13_xml_document/xml_document_spec.rb index 88ce3ae69..3f409f8ed 100644 --- a/13_xml_document/xml_document_spec.rb +++ b/13_xml_document/xml_document_spec.rb @@ -22,50 +22,50 @@ end it "renders an empty tag" do - @xml.hello.should == "" + expect(@xml.hello).to eq("") end it "renders a tag with attributes" do - @xml.hello(:name => 'dolly').should == "" + expect(@xml.hello(:name => 'dolly')).to eq("") end it "renders a randomly named tag" do tag_name = (1..8).map{|i| ('a'..'z').to_a[rand(26)]}.join - @xml.send(tag_name).should == "<#{tag_name}/>" + expect(@xml.send(tag_name)).to eq("<#{tag_name}/>") end it "renders block with text inside" do - @xml.hello do + expect(@xml.hello do "dolly" - end.should == "dolly" + end).to eq("dolly") end it "nests one level" do - @xml.hello do + expect(@xml.hello do @xml.goodbye - end.should == "" + end).to eq("") end it "nests several levels" do xml = XmlDocument.new - xml.hello do + expect(xml.hello do xml.goodbye do xml.come_back do xml.ok_fine(:be => "that_way") end end - end.should == "" + end).to eq("") end it "indents" do @xml = XmlDocument.new(true) - @xml.hello do + expect(@xml.hello do @xml.goodbye do @xml.come_back do @xml.ok_fine(:be => "that_way") end end - end.should == + end).to eq( "\n" + " \n" + " \n" + @@ -73,5 +73,6 @@ " \n" + " \n" + "\n" + ) end end diff --git a/14_array_extensions/array_extensions_spec.rb b/14_array_extensions/array_extensions_spec.rb index a755ac899..4c6b075a2 100755 --- a/14_array_extensions/array_extensions_spec.rb +++ b/14_array_extensions/array_extensions_spec.rb @@ -12,25 +12,25 @@ describe "#sum" do it "has a #sum method" do - [].should respond_to(:sum) + expect([]).to respond_to(:sum) end it "should be 0 for an empty array" do - [].sum.should == 0 + expect([].sum).to eq(0) end it "should add all of the elements" do - [1,2,4].sum.should == 7 + expect([1,2,4].sum).to eq(7) end end describe '#square' do it "does nothing to an empty array" do - [].square.should == [] + expect([].square).to eq([]) end it "returns a new array containing the squares of each element" do - [1,2,3].square.should == [1,4,9] + expect([1,2,3].square).to eq([1,4,9]) end end @@ -38,7 +38,7 @@ it "squares each element of the original array" do array = [1,2,3] array.square! - array.should == [1,4,9] + expect(array).to eq([1,4,9]) end end diff --git a/15_in_words/in_words_spec.rb b/15_in_words/in_words_spec.rb index d9872e767..c7f824cc0 100644 --- a/15_in_words/in_words_spec.rb +++ b/15_in_words/in_words_spec.rb @@ -23,80 +23,80 @@ describe Fixnum do it "reads 0 to 9" do - 0.in_words.should == 'zero' - 1.in_words.should == 'one' - 2.in_words.should == 'two' - 3.in_words.should == 'three' - 4.in_words.should == 'four' - 5.in_words.should == 'five' - 6.in_words.should == 'six' - 7.in_words.should == 'seven' - 8.in_words.should == 'eight' - 9.in_words.should == 'nine' + expect(0.in_words).to eq('zero') + expect(1.in_words).to eq('one') + expect(2.in_words).to eq('two') + expect(3.in_words).to eq('three') + expect(4.in_words).to eq('four') + expect(5.in_words).to eq('five') + expect(6.in_words).to eq('six') + expect(7.in_words).to eq('seven') + expect(8.in_words).to eq('eight') + expect(9.in_words).to eq('nine') end it "reads 10 to 12" do - 10.in_words.should == 'ten' - 11.in_words.should == 'eleven' - 12.in_words.should == 'twelve' + expect(10.in_words).to eq('ten') + expect(11.in_words).to eq('eleven') + expect(12.in_words).to eq('twelve') end it "reads teens" do - 13.in_words.should == 'thirteen' - 14.in_words.should == 'fourteen' - 15.in_words.should == 'fifteen' - 16.in_words.should == 'sixteen' - 17.in_words.should == 'seventeen' - 18.in_words.should == 'eighteen' - 19.in_words.should == 'nineteen' + expect(13.in_words).to eq('thirteen') + expect(14.in_words).to eq('fourteen') + expect(15.in_words).to eq('fifteen') + expect(16.in_words).to eq('sixteen') + expect(17.in_words).to eq('seventeen') + expect(18.in_words).to eq('eighteen') + expect(19.in_words).to eq('nineteen') end it "reads tens" do - 20.in_words.should == 'twenty' - 30.in_words.should == 'thirty' - 40.in_words.should == 'forty' - 50.in_words.should == 'fifty' - 60.in_words.should == 'sixty' - 70.in_words.should == 'seventy' - 80.in_words.should == 'eighty' - 90.in_words.should == 'ninety' + expect(20.in_words).to eq('twenty') + expect(30.in_words).to eq('thirty') + expect(40.in_words).to eq('forty') + expect(50.in_words).to eq('fifty') + expect(60.in_words).to eq('sixty') + expect(70.in_words).to eq('seventy') + expect(80.in_words).to eq('eighty') + expect(90.in_words).to eq('ninety') end it "reads various other numbers less than 100" do - 20.in_words.should == 'twenty' - 77.in_words.should == 'seventy seven' - 99.in_words.should == 'ninety nine' + expect(20.in_words).to eq('twenty') + expect(77.in_words).to eq('seventy seven') + expect(99.in_words).to eq('ninety nine') end it "reads hundreds" do - 100.in_words.should == 'one hundred' - 200.in_words.should == 'two hundred' - 300.in_words.should == 'three hundred' - 123.in_words.should == 'one hundred twenty three' - 777.in_words.should == 'seven hundred seventy seven' - 818.in_words.should == 'eight hundred eighteen' - 512.in_words.should == 'five hundred twelve' - 999.in_words.should == 'nine hundred ninety nine' + expect(100.in_words).to eq('one hundred') + expect(200.in_words).to eq('two hundred') + expect(300.in_words).to eq('three hundred') + expect(123.in_words).to eq('one hundred twenty three') + expect(777.in_words).to eq('seven hundred seventy seven') + expect(818.in_words).to eq('eight hundred eighteen') + expect(512.in_words).to eq('five hundred twelve') + expect(999.in_words).to eq('nine hundred ninety nine') end it "reads thousands" do - 1000.in_words.should == 'one thousand' - 32767.in_words.should == 'thirty two thousand seven hundred sixty seven' - 32768.in_words.should == 'thirty two thousand seven hundred sixty eight' + expect(1000.in_words).to eq('one thousand') + expect(32767.in_words).to eq('thirty two thousand seven hundred sixty seven') + expect(32768.in_words).to eq('thirty two thousand seven hundred sixty eight') end it "reads millions" do - 10_000_001.in_words.should == 'ten million one' + expect(10_000_001.in_words).to eq('ten million one') end it "reads billions" do - 1_234_567_890.in_words.should == 'one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety' + expect(1_234_567_890.in_words).to eq('one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety') end it "reads trillions" do - 1_000_000_000_000.in_words.should == 'one trillion' - 1_000_000_000_001.in_words.should == 'one trillion one' - 1_888_259_040_036.in_words.should == 'one trillion eight hundred eighty eight billion two hundred fifty nine million forty thousand thirty six' + expect(1_000_000_000_000.in_words).to eq('one trillion') + expect(1_000_000_000_001.in_words).to eq('one trillion one') + expect(1_888_259_040_036.in_words).to eq('one trillion eight hundred eighty eight billion two hundred fifty nine million forty thousand thirty six') end end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..d57ec09c7 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,28 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.2.5) + rake (10.4.2) + rspec (3.3.0) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + rake + rspec + +BUNDLED WITH + 1.10.6 From 113e43e47b3ea8e18413e15ff6dd572c931030ad Mon Sep 17 00:00:00 2001 From: Shane Barringer Date: Fri, 30 Oct 2015 14:51:29 -0400 Subject: [PATCH 2/7] slight mod to specs on lesson 3 --- 03_simon_says/simon_says_spec.rb | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/03_simon_says/simon_says_spec.rb b/03_simon_says/simon_says_spec.rb index 2c62be76d..670602496 100644 --- a/03_simon_says/simon_says_spec.rb +++ b/03_simon_says/simon_says_spec.rb @@ -43,10 +43,10 @@ # take one *or* two arguments? # # Hint: *default values* - it "should repeat a number of times" do - expect(repeat("hello", 3)).to eq("hello hello hello") - end - end + # it "should repeat a number of times" do + # expect(repeat("hello", 3)).to eq("hello hello hello") + # end + # end describe "start_of_word" do it "returns the first letter" do @@ -74,23 +74,23 @@ expect(first_word("oh dear")).to eq("oh") end end - - describe "titleize" do - it "capitalizes a word" do - expect(titleize("jaws")).to eq("Jaws") - end - - it "capitalizes every word (aka title case)" do - expect(titleize("david copperfield")).to eq("David Copperfield") - end - - it "doesn't capitalize 'little words' in a title" do - expect(titleize("war and peace")).to eq("War and Peace") - end - - it "does capitalize 'little words' at the start of a title" do - expect(titleize("the bridge over the river kwai")).to eq("The Bridge over the River Kwai") - end - end - -end +# +# describe "titleize" do +# it "capitalizes a word" do +# expect(titleize("jaws")).to eq("Jaws") +# end +# +# it "capitalizes every word (aka title case)" do +# expect(titleize("david copperfield")).to eq("David Copperfield") +# end +# +# it "doesn't capitalize 'little words' in a title" do +# expect(titleize("war and peace")).to eq("War and Peace") +# end +# +# it "does capitalize 'little words' at the start of a title" do +# expect(titleize("the bridge over the river kwai")).to eq("The Bridge over the River Kwai") +# end +# end +# +# end From 0d8b2d214be5ab3ccedded41a2235bfbc8aa8c0d Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 2 Nov 2015 22:36:42 -0500 Subject: [PATCH 3/7] update --- 00_hello/hello.rb | 8 ++++++++ 01_temperature/temperature.rb | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 00_hello/hello.rb create mode 100644 01_temperature/temperature.rb diff --git a/00_hello/hello.rb b/00_hello/hello.rb new file mode 100644 index 000000000..5bee9b283 --- /dev/null +++ b/00_hello/hello.rb @@ -0,0 +1,8 @@ +def hello + "Hello!" +end + + def greet(name) +"Hello, #{name}!" + + end diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb new file mode 100644 index 000000000..8ad5244b3 --- /dev/null +++ b/01_temperature/temperature.rb @@ -0,0 +1,7 @@ +def ftoc(temp) + (temp - 32) * (5.0/9.0) +end +def ctof(temp) + (temp *(9.0/5.0) + 32) + + end From 17f1f0bdf34de32471576a22e061a6dc38689b9d Mon Sep 17 00:00:00 2001 From: benh704 Date: Wed, 4 Nov 2015 15:26:55 -0500 Subject: [PATCH 4/7] Create calculator.rb --- 02_calculator/calculator.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 02_calculator/calculator.rb diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb new file mode 100644 index 000000000..a0dc7f7ec --- /dev/null +++ b/02_calculator/calculator.rb @@ -0,0 +1,8 @@ +def add(x) + x = 0 +end + +def add(y) + y = 4 + + end From 11d9ee74f4b9c0069d6241469f0c01d7ab0ffde8 Mon Sep 17 00:00:00 2001 From: benh704 Date: Wed, 4 Nov 2015 15:34:20 -0500 Subject: [PATCH 5/7] Delete calculator.rb --- 02_calculator/calculator.rb | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 02_calculator/calculator.rb diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb deleted file mode 100644 index a0dc7f7ec..000000000 --- a/02_calculator/calculator.rb +++ /dev/null @@ -1,8 +0,0 @@ -def add(x) - x = 0 -end - -def add(y) - y = 4 - - end From d5a407d3c8a04b9a34577bdd5b88617472687731 Mon Sep 17 00:00:00 2001 From: benh704 Date: Mon, 9 Nov 2015 23:49:24 -0500 Subject: [PATCH 6/7] update --- 03_simon_says/simon_say.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 03_simon_says/simon_say.rb diff --git a/03_simon_says/simon_say.rb b/03_simon_says/simon_say.rb new file mode 100644 index 000000000..2419ca6c1 --- /dev/null +++ b/03_simon_says/simon_say.rb @@ -0,0 +1,17 @@ +def echo (simon_says) + simon_says +end + def shout(simon_says) + simon_says.upcase + end + +def repeat(simon_says) + "#{simon_says } #{ simon_says}" + +end + + +def start_of_word(Hello) + "#{Hello}.gsub(/[a-z] /)" + +end From 8cc702d5115b2517b73b2cc7f0420586534f9366 Mon Sep 17 00:00:00 2001 From: benh704 Date: Tue, 10 Nov 2015 00:01:23 -0500 Subject: [PATCH 7/7] update --- 02_calculator/calculator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 4a9828761..d6fb7412f 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -3,6 +3,7 @@ def add(x,y) x + y + end def subtract(x,y )