UWE-Ruby/week-04 — Issue #1: issues with calling let(:url)
Author: mungruby
Created: 2011-10-28 18:41:20+00:00
State: open

: url_builder_spec.rb

There were a number of different ways I could get the tests to pass, but the simplest was as follows:

# let(:url) {'http://google.com'}
def url
"http://google.com"
end

Else I would get:

C:\projects\ruby\cp110a\week-04>rspec spec/url_builder_spec.rb
F.FFF

Failures:

1) #url_builder should fail
Failure/Error: fail
RuntimeError:
# ./spec/url_builder_spec.rb:42:in `block (2 levels) in '

2) #url_builder when given a single parameter appends the parameters to the ur
l
Failure/Error: url_builder(url, :results => 20).should == "#{url}?results=20"
expected: "http://google.com?results=20&?results=20"
got: "http://google.com?results=20" (using ==)
# ./spec/url_builder_spec.rb:18:in `block (3 levels) in '

3) #url_builder when given multiple parameters should append each parameter with an &
Failure/Error: url_builder(url, :results => '20', :search => 'burgers').should == "#{url}?results=20&search=burgers"
expected: "http://google.com?results=20&search=burgers&?results=20&search=burgers"
got: "http://google.com?results=20&search=burgers" (using ==)
# ./spec/url_builder_spec.rb:27:in `block (3 levels) in '

4) #url_builder when a parameter is nil should ignore the parameter
Failure/Error: url_builder(url, :results => '20', :search => 'burgers', :sort_by => nil).should == "#{url}?results=20&search=burgers"
expected: "http://google.com?results=20&search=burgers&?results=20&search=burgers"
got: "http://google.com?results=20&search=burgers" (using ==)
# ./spec/url_builder_spec.rb:35:in `block (3 levels) in '

Finished in 0 seconds
5 examples, 4 failures

Failed examples:

rspec ./spec/url_builder_spec.rb:41 # #url_builder should fail
rspec ./spec/url_builder_spec.rb:17 # #url_builder when given a single parameter
appends the parameters to the url
rspec ./spec/url_builder_spec.rb:26 # #url_builder when given multiple parameter
s should append each parameter with an &
rspec ./spec/url_builder_spec.rb:34 # #url_builder when a parameter is nil shoul
d ignore the parameter

C:\projects\ruby\cp110a\week-04>

Notice what is showing up in the expected result. With the first test there's no issue, but when you add the hash it changes the expectation. How strange is that?