protest 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,11 +8,11 @@
8
8
  end
9
9
 
10
10
  test "has a name" do
11
- assert @user.name == "John Doe"
11
+ assert_equal "John Doe", @user.name
12
12
  end
13
13
 
14
14
  test "has an email" do
15
- assert @user.email == "john@example.org"
15
+ assert_equal "john@example.org", @user.email
16
16
  end
17
17
  end
18
18
 
@@ -30,23 +30,7 @@ Protest.
30
30
 
31
31
  Or
32
32
 
33
- rip install git://github.com/foca/protest.git v0.2.2
34
-
35
- == Assertions
36
-
37
- You probably wonder why the above example doesn't have any assertion other than
38
- +assert+. Where's +assert_equal+, right? Well, the idea is to keep it slim. If
39
- you want to use more assertions, you're free to define your own. You can also
40
- use all the assertions provided by Test::Unit, by just including them:
41
-
42
- require "test/unit/assertions"
43
-
44
- class Protest::TestCase
45
- include Test::Unit::Assertions
46
- end
47
-
48
- You could also define rspec-like matchers if you like that. See +matchers.rb+ in
49
- the examples directory for an example.
33
+ rip install git://github.com/foca/protest.git v0.2.3
50
34
 
51
35
  == Setup and teardown
52
36
 
@@ -131,16 +115,42 @@ Or you can call the +pending+ method from inside your test.
131
115
  end
132
116
  end
133
117
 
118
+ == Custom assertions
119
+
120
+ By default Protest bundles all the assertions defined in Test::Unit (it
121
+ literally requires them), so check its documentation for all the goodness.
122
+
123
+ If you want to add assertions, just define methods that rely on +assert+ or
124
+ +assert_block+. The former takes a boolean and an optional error message as
125
+ arguments, while the latter takes an optional error message as an argument and
126
+ a block. The assertions is considered to fail if the block evaluates to neither
127
+ +false+ nor +nil+.
128
+
129
+ For example:
130
+
131
+ module AwesomenessAssertions
132
+ def assert_awesomeness(object)
133
+ assert object.awesome?, "#{object.inspect} is not awesome enough"
134
+ end
135
+ end
136
+
137
+ class Protest::TestCase
138
+ include AwesomenessAssertions
139
+ end
140
+
141
+ You could also define rspec-like matchers if you like that style. See
142
+ <tt>matchers.rb</tt> in the examples directory for an example.
143
+
134
144
  == Reports
135
145
 
136
146
  Protest can report the output of a test suite in many ways. The library ships
137
- with a +:progress+ report, and a +:documentation+ report, +:progress+ being the
138
- default.
147
+ with a <tt>:progress</tt> report, and a <tt>:documentation</tt> report,
148
+ <tt>:progress</tt> being the default.
139
149
 
140
150
  === Progress report
141
151
 
142
- Use this report by calling <tt>Protest.report_with(:progress)</tt> (this isn't
143
- needed though, since this is the default report.)
152
+ This is the default option, but you can force this by calling
153
+ <tt>Protest.report_with(:progress)</tt>.
144
154
 
145
155
  The progress report will output the "classic" Test::Unit output of periods for
146
156
  passing tests, "F" for failing assertions, "E" for unrescued exceptions, and
@@ -163,7 +173,7 @@ in that context, one per line. For example:
163
173
  end
164
174
  end
165
175
 
166
- Will output, when run with the +:documentation+ report:
176
+ Will output, when run with the <tt>:documentation</tt> report:
167
177
 
168
178
  A user
169
179
  - has a name (Not Yet Implemented)
@@ -1,4 +1,6 @@
1
1
  module Protest
2
+ VERSION = "0.2.3"
3
+
2
4
  # Exception raised when an assertion fails. See TestCase#assert
3
5
  class AssertionFailed < StandardError; end
4
6
 
@@ -63,6 +65,17 @@ module Protest
63
65
  available_reports.fetch(name).new(*report_args)
64
66
  end
65
67
 
68
+ # Set what object will filter the backtrace. It must respond to
69
+ # +filter_backtrace+, taking a backtrace array and a prefix path.
70
+ def self.backtrace_filter=(filter)
71
+ @backtrace_filter = filter
72
+ end
73
+
74
+ # The object that filters the backtrace
75
+ def self.backtrace_filter
76
+ @backtrace_filter
77
+ end
78
+
66
79
  def self.available_test_cases
67
80
  @test_cases ||= []
68
81
  end
@@ -88,6 +101,7 @@ require "protest/reports/documentation"
88
101
 
89
102
  Protest.autorun = true
90
103
  Protest.report_with(:progress)
104
+ Protest.backtrace_filter = Protest::Utils::BacktraceFilter.new
91
105
 
92
106
  at_exit do
93
107
  Protest.run_all_tests! if Protest.autorun?
@@ -1,10 +1,26 @@
1
1
  require "protest"
2
2
  require "test/unit/assertions"
3
3
  require "action_controller/test_case"
4
- require "webrat"
4
+
5
+ begin
6
+ require "webrat"
7
+ rescue LoadError
8
+ $no_webrat = true
9
+ end
5
10
 
6
11
  module Protest
7
12
  module Rails
13
+ # Exclude rails' files from the errors
14
+ class BacktraceFilter < Utils::BacktraceFilter
15
+ include ::Rails::BacktraceFilterForTestUnit
16
+
17
+ def filter_backtrace(backtrace, prefix=nil)
18
+ super(backtrace, prefix).reject do |line|
19
+ line.starts_with?("/")
20
+ end
21
+ end
22
+ end
23
+
8
24
  # Wrap all tests in a database transaction.
9
25
  #
10
26
  # TODO: make this optional somehow (yet enabled by default) so users of
@@ -38,7 +54,7 @@ module Protest
38
54
  # should use webrat for integration tests. Really.
39
55
  class IntegrationTest < RequestTest
40
56
  include ActionController::Integration::Runner
41
- include Webrat::Methods
57
+ include Webrat::Methods unless $no_webrat
42
58
  end
43
59
  end
44
60
 
@@ -59,4 +75,6 @@ module Protest
59
75
  class << self
60
76
  alias_method :describe, :context
61
77
  end
78
+
79
+ self.backtrace_filter = Rails::BacktraceFilter.new
62
80
  end
@@ -25,6 +25,12 @@ module Protest
25
25
  # your tests by declaring nested contexts inside the class. See
26
26
  # TestCase.context.
27
27
  class TestCase
28
+ begin
29
+ require "test/unit/assertions"
30
+ include Test::Unit::Assertions
31
+ rescue LoadError
32
+ end
33
+
28
34
  # Run all tests in this context. Takes a Report instance in order to
29
35
  # provide output.
30
36
  def self.run(runner)
@@ -46,7 +52,7 @@ module Protest
46
52
  # Add a test to be run in this context. This method is aliased as +it+ and
47
53
  # +should+ for your comfort.
48
54
  def self.test(name, &block)
49
- tests << new(name, &block)
55
+ tests << new(name, caller.at(0), &block)
50
56
  end
51
57
 
52
58
  # Add a setup block to be run before each test in this context. This method
@@ -140,8 +146,9 @@ module Protest
140
146
 
141
147
  # Initialize a new instance of a single test. This test can be run in
142
148
  # isolation by calling TestCase#run.
143
- def initialize(name, &block)
149
+ def initialize(name, location, &block)
144
150
  @test = block
151
+ @location = location
145
152
  @name = name
146
153
  end
147
154
 
@@ -179,7 +186,7 @@ module Protest
179
186
  # Make the test be ignored as pending. You can override the default message
180
187
  # that will be sent to the report by passing it as an argument.
181
188
  def pending(message="Not Yet Implemented")
182
- raise Pending, message
189
+ raise Pending, message, [@location, *caller].uniq
183
190
  end
184
191
 
185
192
  # Name of the test
@@ -39,7 +39,7 @@ module Protest
39
39
  # Filtered backtrace of the assertion. See Protest::Utils::BacktraceFilter
40
40
  # for details on the filtering.
41
41
  def backtrace
42
- @backtrace ||= Utils::BacktraceFilter.filter(raw_backtrace)
42
+ @backtrace ||= Protest.backtrace_filter.filter_backtrace(raw_backtrace)
43
43
  end
44
44
 
45
45
  # Raw backtrace, as provided by the error.
@@ -1,17 +1,23 @@
1
1
  module Protest
2
2
  module Utils
3
3
  # Small utility object to filter an error's backtrace and remove any mention
4
- # of Testicle's own files.
5
- module BacktraceFilter
6
- # Path to the library's 'lib' dir.
7
- BASE_PATH = /^#{Regexp.escape(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))))}/
4
+ # of Protest's own files.
5
+ class BacktraceFilter
6
+ ESCAPE_PATHS = [
7
+ # Path to the library's 'lib' dir.
8
+ /^#{Regexp.escape(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))))}/,
9
+
10
+ # Users certainly don't care about what test loader is being used
11
+ %r[lib/rake/rake_test_loader.rb], %r[bin/testrb]
12
+ ]
8
13
 
9
14
  # Filter the backtrace, removing any reference to files located in
10
15
  # BASE_PATH.
11
- def self.filter(backtrace)
16
+ def filter_backtrace(backtrace, prefix=nil)
17
+ paths = ESCAPE_PATHS + [prefix].compact
12
18
  backtrace.reject do |line|
13
19
  file = line.split(":").first
14
- File.expand_path(file) =~ BASE_PATH
20
+ paths.any? {|path| File.expand_path(file) =~ path }
15
21
  end
16
22
  end
17
23
  end
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "protest"
3
- s.version = "0.2.2"
4
- s.date = "2009-09-17"
3
+ s.version = "0.2.3"
4
+ s.date = "2009-11-14"
5
5
 
6
6
  s.description = "Protest is a tiny, simple, and easy-to-extend test framework"
7
7
  s.summary = s.description
8
- s.homepage = "http://github.com/foca/protest"
8
+ s.homepage = "http://rubyprotest.org"
9
9
 
10
10
  s.authors = ["Nicolás Sanguinetti"]
11
11
  s.email = "contacto@nicolassanguinetti.info"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Nicol\xC3\xA1s Sanguinetti"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-17 00:00:00 -03:00
12
+ date: 2009-11-14 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,7 +41,7 @@ files:
41
41
  - lib/protest/reports/documentation.rb
42
42
  - lib/protest/rails.rb
43
43
  has_rdoc: true
44
- homepage: http://github.com/foca/protest
44
+ homepage: http://rubyprotest.org
45
45
  licenses: []
46
46
 
47
47
  post_install_message:
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements: []
65
65
 
66
66
  rubyforge_project: protest
67
- rubygems_version: 1.3.2
67
+ rubygems_version: 1.3.5
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Protest is a tiny, simple, and easy-to-extend test framework