Monday, February 1, 2010

Two Steps Back

‹prev | My Chain | next›

First up in chain #2 is getting back (as close as possible) to where chain #1 left off. I am going to develop on my Lenovo s10-s netbook, so the first order of business becomes running my specs on a relatively new install Ubuntu 9.10.

I have already done some development on this netbook, so I do not have to install Ruby from scratch along with a bunch of gems. I also have CouchDB installed via apt-get (reported as 0.10.0-0ubuntu3).

So I run my specs, only to find a bunch of these:
...
64)
Haml::SyntaxError in 'recipe.haml a recipe without an image should not include an image'
Unbalanced brackets.
(haml):52:
/home/cstrom/repos/eee-code/spec/spec_helper.rb:26:in `new'
/home/cstrom/repos/eee-code/spec/spec_helper.rb:26:in `render'
./spec/views/recipe.haml_spec.rb:360:
Bah! Did Haml remove my favorite feature of splitting attributes across lines à la:
          %img{:src => "/images/amazon-126X32-w-logo.gif",
:border => 0}
No, Haml still has this, just not in the version in Karmic (2.0.9-1). After a quick apt-get remove and gem install haml, my view specs all pass.

The last obstacle to passing specs are my app specs which reveal an oversight on my part. One of the outputs from chain #1 was the couch_docs gem. It was originally named couch_design_docs, but got a rename after its capabilities increased. The rename did not make it into my spec helpers (they use it to load fixtures and design documents). A quick search and replace and all of my unit tests are passing:
cstrom@whitefall:~/repos/eee-code$ rake
(in /home/cstrom/repos/eee-code)

==
Sinatra app spec
.......................................................

Finished in 6.33 seconds

55 examples, 0 failures

==
Helper specs
..........................................................................................

Finished in 0.39 seconds

90 examples, 0 failures

==
View specs
..............................................................................................................

Finished in 7.72 seconds

110 examples, 0 failures
With unit tests passing, it is time to have a look at the Cucumber integration tests. Sadly, the view ain't pretty:
cstrom@whitefall:~/repos/eee-code$ cucumber features/site.feature
Feature: Site

So that I may explore many wonderful recipes and see the meals in which they were served
As someone interested in cooking
I want to be able to easily explore this awesome site

Scenario: Quickly scanning meals and recipes accessible from the home page # features/site.feature:7
uninitialized constant Webrat::SinatraSession (NameError)
/home/cstrom/repos/eee-code/features/support/env.rb:35
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.6.2/bin/../lib/cucumber/rb_support/rb_language.rb:144:in `call'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.6.2/bin/../lib/cucumber/rb_support/rb_language.rb:144:in `create_world'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.6.2/bin/../lib/cucumber/rb_support/rb_language.rb:95:in `begin_rb_scenario'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.6.2/bin/../lib/cucumber/rb_support/rb_language.rb:130:in `begin_scenario'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.6.2/bin/../lib/cucumber/language_support/language_methods.rb:12:in `before'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.6.2/bin/../lib/cucumber/step_mother.rb:296:in `before'
...
My fresh install of Cucumber onto this netbook is a more recent version than I used to originally develop the application. After consulting the Cucumber / Sinatra documentation, I find that I need to change:
 Webrat.configure do |config|
config.mode = :sinatra
end

World do
session = Webrat::SinatraSession.new
session.extend(Webrat::Matchers)
session.extend(Webrat::HaveTagMatcher)
session
end
To:
 Webrat.configure do |config|
config.mode = :rack
end

class MyWorld
include Rack::Test::Methods
include Webrat::Methods
include Webrat::Matchers

Webrat::Methods.delegate_to_session :response_code, :response_body

def app
Sinatra::Application
end
end

World{MyWorld.new}
Simply put, I need to use rack to test now and alter the "world" (session) a bit. With that, I get:
cstrom@whitefall:~/repos/eee-code$ cucumber features/site.feature
Feature: Site

So that I may explore many wonderful recipes and see the meals in which they were served
As someone interested in cooking
I want to be able to easily explore this awesome site

Scenario: Quickly scanning meals and recipes accessible from the home page # features/site.feature:7
Given 25 yummy meals # features/step_definitions/site.rb:1
And 1 delicious recipe for each meal # features/step_definitions/site.rb:30
And the first 5 recipes are Italian # features/step_definitions/site.rb:61
And the second 10 recipes are Vegetarian # features/step_definitions/site.rb:74
When I view the site's homepage # features/step_definitions/site.rb:87
HTTP status code 500 (RestClient::RequestFailed)
/usr/lib/ruby/1.8/net/http.rb:543:in `start'
./features/support/../../eee.rb:38:in `GET /'
(eval):2:in `visit'
./features/step_definitions/site.rb:88:in `/^I view the site.s homepage$/'
features/site.feature:13:in `When I view the site's homepage'
Then I should see the 10 most recent meals prominently displayed # features/step_definitions/site.rb:92
And the prominently displayed meals should include a thumbnail image # features/step_definitions/site.rb:99
And the prominently displayed meals should include the recipe titles # features/step_definitions/site.rb:103
When I click on the first meal # features/step_definitions/site.rb:108
Then I should see the meal page # features/step_definitions/site.rb:116
And the Italian category should be highlighted # features/step_definitions/site.rb:121
When I click on the recipe in the menu # features/step_definitions/site.rb:127
Then I should see the recipe page # features/step_definitions/site.rb:152
And the Italian category should be highlighted # features/step_definitions/site.rb:121
When I click the Italian category # features/step_definitions/site.rb:131
Then I should see 5 Italian recipes # features/step_definitions/site.rb:157
When I click the site logo # features/step_definitions/site.rb:112
Then I should see the homepage # features/step_definitions/site.rb:163
When I click the recipe link under the 6th meal # features/step_definitions/site.rb:135
Then I should see the recipe page # features/step_definitions/site.rb:152
And the Vegetarian category should be highlighted # features/step_definitions/site.rb:121
While this might not seem like progress, I am now failing where I want to—CouchDB it generating 500 failures because my views stink. I'll start fixing them tomorrow.

Day #1

No comments:

Post a Comment