undefined local variable or method `response' (with Sinatra)

200 views
Skip to first unread message

doug livesey

unread,
Oct 14, 2009, 3:58:09 PM10/14/09
to web...@googlegroups.com
Hi -- I'm trying to cuke up a Sinatra app (generated with the default monk generator), and having a few problems.
My current one, that I've no idea how to resolve, is that I can't access the response object that I so take for granted in Rails.

Here is my env.rb
<env.rb>
app_file = File.join(File.dirname(__FILE__), *%w[.. .. init.rb])
require app_file
# Force the application name because polyglot breaks the auto-detection logic.
Sinatra::Application.app_file = app_file

require 'spec/expectations'
require 'rack/test'
require 'webrat'

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}
</env.rb>

Here is my feature file:
<test.feature>
Feature: Test
  
  I want to see if I can get Cucumber working with Sinatra.

  Scenario: Browsing to the root page
    Given I have browsed to the root page
    Then I should see "Hello, Cruel World!"
</test.feature>

And here is my steps file:
<test_steps.rb>
Given /^I have browsed to the root page$/ do
  visit( "/" )
end

Then /^I should see "([^\"]*)"$/ do |value|
  response.should contain( value )
end

</test_steps.rb>

The first step comes back green, but the second gives me the following error:
      undefined local variable or method `response' for #<MyWorld:0x1023d1d98> (NameError)
      features/test.feature:7:in `Then I should see "Hello, Cruel World!"'

Can anyone offer any advice on what to do to fix this, or where to look to gain more insight?
Thanks,
   Doug.

Ben Lovell

unread,
Oct 14, 2009, 4:45:43 PM10/14/09
to web...@googlegroups.com
2009/10/14 doug livesey <bio...@gmail.com>
Hi -- I'm trying to cuke up a Sinatra app (generated with the default monk generator), and having a few problems.


try: last_response instead.

Cheers,
Ben

doug livesey

unread,
Oct 14, 2009, 5:23:52 PM10/14/09
to web...@googlegroups.com
Perfect, thankyou!
Why did you suggest that?
   Doug.

2009/10/14 Ben Lovell <benjami...@gmail.com>

Damian Janowski

unread,
Oct 14, 2009, 11:44:09 PM10/14/09
to web...@googlegroups.com
On Wed, Oct 14, 2009 at 6:23 PM, doug livesey <bio...@gmail.com> wrote:
> Perfect, thankyou!
> Why did you suggest that?

Because that's what Rack::Test uses.

Reply all
Reply to author
Forward
0 new messages