Created
May 7, 2012 13:33
-
-
Save peterhellberg/2627790 to your computer and use it in GitHub Desktop.
Testing Sinatra helpers (in isolation) that depend on the params hash being present
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
module MyHelpers | |
def foo | |
"#{params[:bar]}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require_relative "spec_helper" | |
require_relative "../lib/my_helpers.rb" | |
class FakeApp | |
attr_accessor :params | |
include MyHelpers | |
def initialize(params = {}) | |
@params = params | |
end | |
end | |
describe MyHelpers do | |
subject { FakeApp } | |
describe "foo" do | |
it "returns the bar param" do | |
s(bar: 'baz').foo.must_equal 'baz' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require 'bundler' | |
Bundler.setup | |
Bundler.require | |
require 'minitest/pride' | |
require 'minitest/autorun' | |
require 'minitest/spec' | |
require 'rack/test' | |
class MiniTest::Spec | |
include Rack::Test::Methods | |
end | |
def s(*args) | |
subject.new(*args) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment