45. $ rake spec:request
.**......
Pending:
resource(:pubs) GET contains a list of pubs (TODO)
Called from ./spec/requests/pubs_spec.rb:21
resource(:pubs) GET has a list of pubs (TODO)
Called from ./spec/requests/pubs_spec.rb:33
Finished in 0.322787 seconds
9 examples, 0 failures, 2 pending
run specs
48. $ vim spec/requests/pubs_spec.rb
...
it quot;contains a sorted list of pubsquot; do
@response.should have_xpath(quot;//h3[contains(.,'Cheapest')]quot;)
@response.should have_xpath(quot;//h3[contains(.,'Nearest')]quot;)
end
request specs
51. $ rake spec:request
Pending:
resource(:pubs) GET has a list of pubs (TODO)
Called from ./spec/requests/pubs_spec.rb:33
1)
'resource(:pubs) GET contains a sorted list of pubs' FAILED
expected following text to match xpath //h3[contains(.,'Cheapest')]’
./spec/requests/pubs_spec.rb:21:
Finished in 0.411139 seconds
9 examples, 1 failure, 1 pending
run specs
61. $ bzr mv app/views/pubs/index.html.erb
app/views/pubs/index.html.haml
$ vim app/views/pubs/index.html.haml
%h3 Nearest
%h3 Cheapest
$ rake spec:request
Pending:
resource(:pubs) GET has a list of pubs (TODO)
Called from ./spec/requests/pubs_spec.rb:33
Finished in 0.389194 seconds
9 examples, 0 failures, 1 pending
hamlise view tests pass!
65. $ vim spec/models/pubs_spec.rb
1. it quot;should have name, address, pricequot; do
@pubs.each do |pub|
pub.name.should_not be_nil
pub.address.should_not be_nil
pub.price.should_not be_nil
end
end
model specs
66. $ vim spec/models/pubs_spec.rb
2. it quot;should handle different url formatsquot; do
@pubs.each do |pub|
pub.url = 'mygreatpub.com.au'
pub.save.should be_true
pub.url = 'http://mygreatpub.com.au/'
pub.save.should be_true
end
end
model specs
67. $ vim spec/models/pubs_spec.rb
3. it quot;should consistently format + store urlsquot; do
@pubs.each do |pub|
adjective = %w[great swanky awesome stylish][rand(4)]
pub.url = quot;#{adjective}pub.com.auquot;
pub.save.should be_true
pub.url.should =~ /^http://.+/$/
end
end
model specs
70. $ vim spec/models/pubs_spec.rb
before(:each) do
@pubs = 10.of { Pub.generate }
end
$ vim spec/spec_fixtures.rb
require 'dm-sweatshop'
Pub.fixture do
{
:name => ( name = %w[John Jane Jerry Justin][rand(4)] + quot;'s Pubquot;),
:price => (1..30).to_a[rand(30)],
:address => quot;#{(40..166).to_a[rand(126)]} Spring quot; + %w[Street Road Avenue][rand(3)],
:url => quot;http://#{name.gsub(/W/, '').downcase}.com/quot;
}
end
model specs
73. $ rake spec:models
1)
NameError in 'Pub should have name, address, price'
address= is not a public property
2)
NameError in 'Pub should handle different url formats'
address= is not a public property
3)
NameError in 'Pub should consistently format + store urls'
address= is not a public property
Finished in 0.252169 seconds
3 examples, 3 failures
run specs
83. $ vim spec/requests/pubs_spec.rb
...
it quot;contains a list of cheapest pubsquot; do
@response.should have_xpath(quot;//div[@id=’cheapest’]quot;)
@response.should have_xpath(quot;//div[@id=’cheapest’]//table//tr//td[@class='name']quot;)
@response.should have_xpath(quot;//div[@id=’cheapest’]//table//tr//td[@class='address']quot;)
@response.should have_xpath(quot;//div[@id=’cheapest’]//table//tr//td[contains(@class,'price')]quot;)
end
request specs
86. $ rake spec:request
Pending:
resource(:pubs) GET has a list of pubs (TODO)
Called from ./spec/requests/pubs_spec.rb:37
1)
'resource(:pubs) GET contains a list cheapest pubs' FAILED
expected following text to match xpath //div[@id='cheapest']
./spec/requests/pubs_spec.rb:26:
Finished in 0.411139 seconds
10 examples, 1 failure, 1 pending
run specs
94. $ rake spec:request
Pending:
resource(:pubs) GET has a list of pubs (TODO)
Called from ./spec/requests/pubs_spec.rb:37
Finished in 0.854704 seconds
10 examples, 0 failures, 1 pending
run specs
106. $ vim public/javascripts/application.js
window.addEvent('domready', function() {
if (GBrowserIsCompatible()) {
var map = new GMap2($(quot;mapquot;));
map.enableScrollWheelZoom();
map.setCenter(new GLatLng(-33.86336, 151.207151), 12);
var geocoder = new GClientGeocoder();
/* geocode top-ten addresses */
$$('div#cheapest tr').each( function(element) {
showAddress(map, geocoder, element);
});
}
});
dash o’ javascript
107. $ vim public/javascripts/application.js
function showAddress(map, geocoder, element) {
var name = element.getElements('td.name a').get('html');
var address = element.getChildren('td.address').get('html');
var price = element.getElements('td.price').get('html');
var link = element.getElements('td.name a').get('href');
geocoder.getLatLng(address, function(point) {
if (point) {
var marker = new GMarker(point);
marker.bindInfoWindowHtml(quot;<h4>quot; + name + quot;</h4>quot; + ... );
map.addOverlay(marker);
}
});
}
custom geocoder