| 1 |
$TESTING=true |
|---|
| 2 |
require 'timeout' |
|---|
| 3 |
require 'open-uri' |
|---|
| 4 |
require 'net/http' |
|---|
| 5 |
require 'rubygems' |
|---|
| 6 |
require 'spec' |
|---|
| 7 |
require 'mocha' |
|---|
| 8 |
require 'hpricot' |
|---|
| 9 |
$:.push File.join(File.dirname(__FILE__), '..', 'lib') |
|---|
| 10 |
$:.push File.join(File.dirname(__FILE__), '..', 'lib', 'merb', 'server') |
|---|
| 11 |
require File.join(File.dirname(__FILE__), '..', 'lib', 'merb', 'config') |
|---|
| 12 |
Merb::Config.setup |
|---|
| 13 |
require 'merb' |
|---|
| 14 |
require 'merb/test/helper' |
|---|
| 15 |
|
|---|
| 16 |
FIXTURES = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) unless defined?(FIXTURES) |
|---|
| 17 |
def require_fixtures(path) |
|---|
| 18 |
require File.expand_path(File.join(FIXTURES, path)) |
|---|
| 19 |
end |
|---|
| 20 |
|
|---|
| 21 |
require File.join(File.dirname(__FILE__), "spec_helpers", "url_shared_behaviour") |
|---|
| 22 |
|
|---|
| 23 |
Spec::Runner.configure do |config| |
|---|
| 24 |
config.include(Merb::Test::Helper) |
|---|
| 25 |
config.include(Merb::Test::RspecMatchers) |
|---|
| 26 |
# config.include(Merb::Test::MerbRspecControllerRedirect) |
|---|
| 27 |
end |
|---|
| 28 |
|
|---|
| 29 |
# Creates a new controller, e.g. |
|---|
| 30 |
# c = new_controller('index', Examples) do |request| |
|---|
| 31 |
# request.post_body = "blah" |
|---|
| 32 |
# end |
|---|
| 33 |
def new_controller(action = 'index', controller = nil, additional_params = {}) |
|---|
| 34 |
request = OpenStruct.new |
|---|
| 35 |
request.params = {:action => action, :controller => (controller.to_s || "Test")} |
|---|
| 36 |
request.params.update(additional_params) |
|---|
| 37 |
request.cookies = {} |
|---|
| 38 |
request.accept ||= '*/*' |
|---|
| 39 |
|
|---|
| 40 |
yield request if block_given? |
|---|
| 41 |
|
|---|
| 42 |
response = OpenStruct.new |
|---|
| 43 |
response.read = "" |
|---|
| 44 |
(controller || Merb::Controller).build(request, response) |
|---|
| 45 |
end |
|---|
| 46 |
|
|---|
| 47 |
class Merb::Controller |
|---|
| 48 |
require "lib/merb/session/memory_session" |
|---|
| 49 |
Merb::MemorySessionContainer.setup |
|---|
| 50 |
include ::Merb::SessionMixin |
|---|
| 51 |
self.session_secret_key = "footo the bar to the baz" |
|---|
| 52 |
end |
|---|
| 53 |
|
|---|
| 54 |
class String |
|---|
| 55 |
def clean |
|---|
| 56 |
Hpricot(chomp).to_s |
|---|
| 57 |
end |
|---|
| 58 |
end |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
# -- Global custom matchers -- |
|---|
| 62 |
|
|---|
| 63 |
# A better +be_kind_of+ with more informative error messages. |
|---|
| 64 |
# |
|---|
| 65 |
# The default +be_kind_of+ just says |
|---|
| 66 |
# |
|---|
| 67 |
# "expected to return true but got false" |
|---|
| 68 |
# |
|---|
| 69 |
# This one says |
|---|
| 70 |
# |
|---|
| 71 |
# "expected File but got Tempfile" |
|---|
| 72 |
|
|---|
| 73 |
class BeKindOf |
|---|
| 74 |
|
|---|
| 75 |
def initialize(expected) # + args |
|---|
| 76 |
@expected = expected |
|---|
| 77 |
end |
|---|
| 78 |
|
|---|
| 79 |
def matches?(target) |
|---|
| 80 |
@target = target |
|---|
| 81 |
@target.kind_of?(@expected) |
|---|
| 82 |
end |
|---|
| 83 |
|
|---|
| 84 |
def failure_message |
|---|
| 85 |
"expected #{@expected} but got #{@target.class}" |
|---|
| 86 |
end |
|---|
| 87 |
|
|---|
| 88 |
def negative_failure_message |
|---|
| 89 |
"expected #{@expected} to not be #{@target.class}" |
|---|
| 90 |
end |
|---|
| 91 |
|
|---|
| 92 |
def description |
|---|
| 93 |
"be_kind_of #{@target}" |
|---|
| 94 |
end |
|---|
| 95 |
|
|---|
| 96 |
end |
|---|
| 97 |
|
|---|
| 98 |
def be_kind_of(expected) # + args |
|---|
| 99 |
BeKindOf.new(expected) |
|---|
| 100 |
end |
|---|
| 101 |
|
|---|