Webrat & Sinatra

7 views
Skip to first unread message

Arco

unread,
Nov 5, 2009, 11:15:05 AM11/5/09
to webrat
Here's my sinatra app:

require 'rubygems'; require 'sinatra'
get '/' do "hello world" end

What is the simplest way to get webrat working against this ??

I've found a bunch of tutorials out there - all of which seem to be
out of date - I can't get this to work!!

If someone could post a working example I would greatly appreciate it.

Damian Janowski

unread,
Nov 5, 2009, 11:24:46 AM11/5/09
to web...@googlegroups.com
On Thu, Nov 5, 2009 at 1:15 PM, Arco <akl...@gmail.com> wrote:
>
> Here's my sinatra app:
>
>    require 'rubygems'; require 'sinatra'
>    get '/' do "hello world" end
>
> What is the simplest way to get webrat working against this ??
>
> I've found a bunch of tutorials out there - all of which seem to be
> out of date - I can't get this to work!!

This should get you going:
http://github.com/monkrb/skeleton/blob/master/test/test_helper.rb

Plus, remember not to use this:

enable :sessions

Rather, call the middleware directly:

use Rack::Session::Cookie

D.

Arco

unread,
Nov 5, 2009, 12:08:02 PM11/5/09
to webrat
Thanks for the link - but i'm looking for a simple standalone example.

The simplest example I was able to find is on the Webrat wiki. See
http://wiki.github.com/brynary/webrat/sinatra - simple but the code
doesn't work...

Here is my sinatra app - app.rb:
require 'rubygems'; require 'sinatra'
get '/' do 'hello world' end

Here is my modified test example - test.rb:
require "rubygems"
require "webrat"
require "webrat/sinatra"
require "test/unit"
require "app"

Webrat.configure do |config|
config.mode = :rack
end

class AppTest < Test::Unit::TestCase
include Webrat::Methods
include Webrat::Matchers

def test_it_works
visit "/"
assert_contain("hello world")
end
end

I run this with `ruby test.rb`, and get an error:
ArgumentError: tried to create Proc object without a block
...
...

I'm using Sinatra 0.9.4, Webrat 0.5.3, Ubuntu 9.04, Ruby 1.8.7.

How can I make this work ???

Damian Janowski

unread,
Nov 5, 2009, 12:25:19 PM11/5/09
to web...@googlegroups.com
On Thu, Nov 5, 2009 at 2:08 PM, Arco <akl...@gmail.com> wrote:
>
> Thanks for the link - but i'm looking for a simple standalone example.

http://gist.github.com/227219

Arco

unread,
Nov 5, 2009, 12:38:26 PM11/5/09
to webrat
Damian - thanks so much!

I got it working myself a couple seconds ago - was going to post my
solution - yours is cleaner :-)

thanks again, Andy

Damian Janowski

unread,
Nov 5, 2009, 1:04:58 PM11/5/09
to web...@googlegroups.com
On Thu, Nov 5, 2009 at 2:38 PM, Arco <akl...@gmail.com> wrote:
>
> Damian - thanks so much!

No problem, I updated the Webrat wiki too.

Michel Martens

unread,
Nov 5, 2009, 11:23:13 AM11/5/09
to web...@googlegroups.com
On Thu, Nov 5, 2009 at 1:15 PM, Arco <akl...@gmail.com> wrote:
>
> Here's my sinatra app:
>
>    require 'rubygems'; require 'sinatra'
>    get '/' do "hello world" end
>
> What is the simplest way to get webrat working against this ??
>
> I've found a bunch of tutorials out there - all of which seem to be
> out of date - I can't get this to work!!
>

Check Monk: http://monkrb.com

--
Michel

Reply all
Reply to author
Forward
0 new messages