Testing helpers in Sinatra

How do you test your helper methods in a Sinatra::Base app?

1
2
3
4
5
6
7
module FundAStache
  module Helpers    
    def logged_in?
      false # you shall not pass...
    end
  end
end

Include them in your tests…

1
2
3
4
class FundastacheUserTest < Test::Unit::TestCase
  include Rack::Test::Methods
  include FundAStache::Helpers
  ...
Posted: March 9th, 2010 | Author: jay | Filed under: Code | Tags: , , , , , | No Comments »

Here’s what my test_helper.rb file looks like…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
require 'fundastache'
require 'test/unit'
require "rack/test"
require "rack/flash/test"
 
ENV['RACK_ENV'] = 'test'
 
# set test environment
set :environment, :test
set :run, false
set :raise_errors, true
set :logging, false
 
DataMapper.setup(:default, "sqlite3::memory:") 
DataMapper.auto_migrate!
Posted: March 9th, 2010 | Author: jay | Filed under: Code | Tags: , , , | No Comments »

Testing Rack::Flash in Sinatra

Here’s a slightly dumb way to test Rack::Flash in a Sinatra app…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require File.dirname(__FILE__) + '/../test_helper.rb'
 
module FundAStache
  class Application
    get '/rack_flash_test' do
      flash[:notice]='rack flash is working'
      haml :index
    end
  end
end
 
class FundastacheTest < Test::Unit::TestCase
  include Rack::Test::Methods
 
  def flash
    last_request.env['x-rack.flash']
  end
 
  def app
    @app ||= FundAStache::Application
  end
 
  def test_rack_flash_working
    # see fake route above...
    get '/rack_flash_test'
    assert_not_nil flash
    assert last_response.body.include?("rack flash is working")
  end
end
Posted: March 8th, 2010 | Author: admin | Filed under: Code | Tags: , , , , | 1 Comment »

OpenID for Fund-A-Stache

Leaning towards using OpenID for the login for Fund-A-Stache.

Posted: March 8th, 2010 | Author: admin | Filed under: Code | Tags: , , , | No Comments »

Looking for a pretty code viewer for this blog…

* Updated: Working thanks to this WP plugin.

Here’s some code as a test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require File.dirname(__FILE__) + '/../test_helper.rb'
 
class FundastacheTest < Test::Unit::TestCase
  include Rack::Test::Methods
 
  def app
    @app ||= FundAStache::Application
  end
 
  def test_home_page_ok
    get '/'
    assert last_response.ok?
  end
 
  def test_404_error
    get '/does_not_exist'
    assert !last_response.ok?
  end
 
  def test_custom_404_error
    get '/does_not_exist'
    assert last_response.body.include?("what\'cha lookin\' for?")    
  end
 
end

and I want it to look nice. How can we do that with WordPress?

Posted: March 7th, 2010 | Author: admin | Filed under: Code | Tags: , , , | No Comments »