Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Testing Sinatra helper methods
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike Barton  
View profile  
 More options Jul 26 2009, 6:01 pm
From: Mike Barton <barton.mich...@gmail.com>
Date: Sun, 26 Jul 2009 15:01:47 -0700 (PDT)
Local: Sun, Jul 26 2009 6:01 pm
Subject: Testing Sinatra helper methods
Hi,

Is there a way to test the methods defined in the 'helper' block
within the sinatra application?
I'm using Rack::Test and following the sinatra documentation on the
sinatrarb site, but I can seem to find anything about testing the
helper methods.

Thanks

Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christer Nilsson  
View profile  
 More options Jul 26 2009, 6:53 pm
From: Christer Nilsson <janchrister.nils...@gmail.com>
Date: Mon, 27 Jul 2009 00:53:52 +0200
Local: Sun, Jul 26 2009 6:53 pm
Subject: Re: Testing Sinatra helper methods

| Is there a way to test the methods defined in the 'helper' block
| within the sinatra application?
| I'm using Rack::Test and following the sinatra documentation on the
| sinatrarb site, but I can seem to find anything about testing the
| helper methods.
|
| Mike
I've asked this question before, and the answer was: Use black box testing.
That is, just simulate get,put,post and delete and check the results using
e.g. Hpricot.

Personally, I sometimes prefer deeper testing.
I've accomplished that by defining get '/test'.

hope this helps

/Christer


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Damian Janowski  
View profile  
 More options Jul 26 2009, 7:31 pm
From: Damian Janowski <damian.janow...@gmail.com>
Date: Sun, 26 Jul 2009 20:31:22 -0300
Local: Sun, Jul 26 2009 7:31 pm
Subject: Re: Testing Sinatra helper methods

On Sun, Jul 26, 2009 at 7:01 PM, Mike Barton<barton.mich...@gmail.com> wrote:
> Is there a way to test the methods defined in the 'helper' block
> within the sinatra application?
> I'm using Rack::Test and following the sinatra documentation on the
> sinatrarb site, but I can seem to find anything about testing the
> helper methods.

Are you using classic-style?
What testing framework are you using?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kematzy  
View profile  
 More options Jul 26 2009, 10:49 pm
From: Kematzy <kema...@googlemail.com>
Date: Mon, 27 Jul 2009 10:49:59 +0800
Local: Sun, Jul 26 2009 10:49 pm
Subject: Re: Testing Sinatra helper methods

Mike,

I was struggling with this issue as well before, but think I've solved  
it now.

In my spec_helper.rb (using RSpec)  I create a test app:

class MyTestApp < MyApp # the name of your app or S::B

   get '/tests' do
     case params[:engine]
     when 'erb'
       erb(params[:view], :layout => params[:layout] )
     when 'haml'
       haml(params[:view], :layout => params[:layout] )
     else
       params.inspect
     end
   end

end

Then the Test::Unit::TestCase declaration looks like this: (also in  
spec_helper.rb)

class Test::Unit::TestCase
   include Rack::Test::Methods

   # I declare the app value in before blocks in each actual spec file,
   # to prevent confusions between multiple apps (ie: testing with  
options on/off)
   # def app
   #   MyTestApp.new
   # end

   def setup
     Sinatra::Base.set :environment, :test
   end

   def erb_app(view, options = {})
     options = {:layout => '<%= yield %>', :url  => '/
tests' }.merge(options)
     get options[:url], :view => view, :layout =>  
options[:layout], :engine => :erb
   end

   def haml_app(view, options = {})
     options = {:layout => '= yield ', :url  => '/
tests' }.merge(options)
      get options[:url], :view => view, :layout =>  
options[:layout], :engine => :haml
   end

end

Finally, in my tests I just do this:

   it "should return ...." do
     erb_app '<%= name_of_my_helper_method %>'
     last_response.body.should == 'expected result'
   end

This works quite well I would say, and I only wish I had thought about  
it earlier.

On Jul 27, 2009, at 6:01 AM, Mike Barton wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Barton  
View profile  
 More options Jul 28 2009, 6:08 pm
From: Mike Barton <barton.mich...@gmail.com>
Date: Tue, 28 Jul 2009 15:08:59 -0700 (PDT)
Local: Tues, Jul 28 2009 6:08 pm
Subject: Re: Testing Sinatra helper methods
Thanks for your replies everyone.
I've been using rspec with rack::test for TDD on my models etc.
From your replies it looks I should switch to cucumber and webrat to
black box test the expected HTML.

Thanks again

On Jul 27, 3:49 am, Kematzy <kema...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Lovell  
View profile  
 More options Aug 2 2009, 6:02 am
From: Ben Lovell <benjamin.lov...@gmail.com>
Date: Sun, 2 Aug 2009 11:02:00 +0100
Subject: Re: Testing Sinatra helper methods

2009/7/28 Mike Barton <barton.mich...@gmail.com>

> Thanks for your replies everyone.
> I've been using rspec with rack::test for TDD on my models etc.
> From your replies it looks I should switch to cucumber and webrat to
> black box test the expected HTML.

> Thanks again

May I just add, there is a fantastic series of blog posts where this
dude evolves his sinatra/couchdb app through both cukes/webrat and
rspec here:

http://japhr.blogspot.com/

Definitely worth a look for some pointers.

Cheers,
B


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »