wycats / merb-core

Merb Core: All you need. None you don't.

This URL has Read+Write access

merb-core / spec / spec_helper.rb
615713fd » wycats 2008-01-11 Initial checkin 1 $TESTING=true
70190ddb » Yehuda Katz 2008-01-31 Scads of tests. 2 require "rubygems"
86969139 » Yehuda Katz 2008-01-31 rake rcov works now with th... 3 require "spec"
57676b3c » wycats 2008-01-17 Slight renaming 4 require File.join(File.dirname(__FILE__), "..", "lib", "merb-core")
eab8c1f0 » hassox 2008-02-12 Includes the get, post, put... 5
261067a4 » wycats 2008-08-08 Additional refactor of the ... 6 default_options = {:environment => 'test', :adapter => 'runner'}
7 options = default_options.merge($START_OPTIONS || {})
2369da6c » fabien 2008-09-07 Merged in new-sessions branch 8 Merb.start_environment(options)
1cbab3fc » ivey 2008-06-01 Revert ca92bdfc89afda04cbb4... 9
615713fd » wycats 2008-01-11 Initial checkin 10 # -- Global custom matchers --
11
12 # A better +be_kind_of+ with more informative error messages.
13 #
ceb783fc » michaelklishin 2008-05-13 Sweet empty lines managemen... 14 # The default +be_kind_of+ just says
615713fd » wycats 2008-01-11 Initial checkin 15 #
16 # "expected to return true but got false"
17 #
18 # This one says
19 #
20 # "expected File but got Tempfile"
21
1fa4c67b » wycats 2008-01-13 First public API specs: 22 module Merb
23 module Test
24 module RspecMatchers
63ba7aee » wycats 2008-08-06 Add more edge-case specs to... 25 class IncludeLog
26 def initialize(expected)
27 @expected = expected
28 end
29
30 def matches?(target)
fdc4ec0c » wycats 2008-09-26 Fix logger helper 31 target.rewind
32 @text = target.read
4dd15027 » wycats 2008-08-19 Fixes up a bunch of specs Comment 33 @text =~ (String === @expected ? /#{Regexp.escape @expected}/ : @expected)
63ba7aee » wycats 2008-08-06 Add more edge-case specs to... 34 end
35
36 def failure_message
37 "expected to find `#{@expected}' in the log but got:\n" <<
38 @text.map {|s| " #{s}" }.join
39 end
40
41 def negative_failure_message
42 "exected not to find `#{@expected}' in the log but got:\n" <<
43 @text.map {|s| " #{s}" }.join
44 end
45
46 def description
47 "include #{@text} in the log"
48 end
49 end
50
1fa4c67b » wycats 2008-01-13 First public API specs: 51 class BeKindOf
52 def initialize(expected) # + args
53 @expected = expected
54 end
55
56 def matches?(target)
57 @target = target
58 @target.kind_of?(@expected)
59 end
60
61 def failure_message
62 "expected #{@expected} but got #{@target.class}"
63 end
64
65 def negative_failure_message
66 "expected #{@expected} to not be #{@target.class}"
67 end
68
69 def description
70 "be_kind_of #{@target}"
71 end
72 end
73
74 def be_kind_of(expected) # + args
75 BeKindOf.new(expected)
76 end
63ba7aee » wycats 2008-08-06 Add more edge-case specs to... 77
78 def include_log(expected)
79 IncludeLog.new(expected)
80 end
1fa4c67b » wycats 2008-01-13 First public API specs: 81 end
460780b9 » Hampton Catlin 2008-02-01 Repairing a little of the d... 82
39791e6f » wycats 2008-01-14 Very close to controllers w... 83 module Helper
84 def running(&blk) blk; end
ceb783fc » michaelklishin 2008-05-13 Sweet empty lines managemen... 85
39791e6f » wycats 2008-01-14 Very close to controllers w... 86 def executing(&blk) blk; end
ceb783fc » michaelklishin 2008-05-13 Sweet empty lines managemen... 87
39791e6f » wycats 2008-01-14 Very close to controllers w... 88 def doing(&blk) blk; end
ceb783fc » michaelklishin 2008-05-13 Sweet empty lines managemen... 89
90 def calling(&blk) blk; end
39791e6f » wycats 2008-01-14 Very close to controllers w... 91 end
615713fd » wycats 2008-01-11 Initial checkin 92 end
93 end
94
1fa4c67b » wycats 2008-01-13 First public API specs: 95 Spec::Runner.configure do |config|
39791e6f » wycats 2008-01-14 Very close to controllers w... 96 config.include Merb::Test::Helper
97 config.include Merb::Test::RspecMatchers
966cf5e8 » bryansray 2008-08-26 First pass at adding in CSR... Comment 98 config.include Merb::Test::Rspec::ViewMatchers
ceb783fc » michaelklishin 2008-05-13 Sweet empty lines managemen... 99 config.include Merb::Test::RequestHelper
80b01f99 » carllerche 2008-09-20 Significant router refactor... 100 config.include Merb::Test::RouteHelper
63ba7aee » wycats 2008-08-06 Add more edge-case specs to... 101
5f56c20d » fabien 2008-09-24 Refactored Kernel#dependenc... 102 def reset_dependency(name, const = nil)
103 Object.send(:remove_const, const) if const && Object.const_defined?(const)
104 Merb::BootLoader::Dependencies.dependencies.delete_if do |d|
105 d.name == name
106 end
107 $LOADED_FEATURES.delete("#{name}.rb")
108 end
109
4dd15027 » wycats 2008-08-19 Fixes up a bunch of specs Comment 110 def with_level(level)
fdc4ec0c » wycats 2008-09-26 Fix logger helper 111 Merb::Config[:log_stream] = StringIO.new
112 Merb::Config[:log_level] = level
113 Merb.logger = nil
4dd15027 » wycats 2008-08-19 Fixes up a bunch of specs Comment 114 yield
fdc4ec0c » wycats 2008-09-26 Fix logger helper 115 Merb::Config[:log_stream]
4dd15027 » wycats 2008-08-19 Fixes up a bunch of specs Comment 116 end
117
63ba7aee » wycats 2008-08-06 Add more edge-case specs to... 118 def capture(stream)
119 begin
120 stream = stream.to_s
121 eval "$#{stream} = StringIO.new"
122 yield
123 result = eval("$#{stream}").string
124 ensure
125 eval("$#{stream} = #{stream.upcase}")
126 end
127
128 result
129 end
130
131 alias silence capture
ceb783fc » michaelklishin 2008-05-13 Sweet empty lines managemen... 132 end