baretest 0.4.0.pre1 → 0.4.0.pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,23 +43,6 @@ module BareTest
43
43
  #
44
44
  module Support
45
45
 
46
- # Creates global setup and teardown callbacks that are needed by some of
47
- # BareTest::Assertion::Support's methods.
48
- #
49
- module SetupAndTeardown
50
-
51
- # Install the setup and teardown callbacks.
52
- def self.extended(run_obj) # :nodoc:
53
- run_obj.init do
54
- suite.teardown do
55
- ::BareTest.clean_touches(self) # instance evaled, self is the assertion
56
- end
57
- end
58
- end
59
-
60
- ::BareTest.extender << self
61
- end
62
-
63
46
  # FIXME: undocumented and untested
64
47
  # It's really ugly. You should use a mock instead.
65
48
  def yields(subject, meth, args, *expected)
@@ -116,9 +116,9 @@ module BareTest
116
116
  status = Status.new(self, :pending)
117
117
  else
118
118
  context = ::BareTest::Assertion::Context.new(self)
119
- status = execute_phase(:setup, context, with_setup) if with_setup
119
+ status = execute_phase(:setup, context, with_setup.map { |s| [[s.value], s.block] }) if with_setup
120
120
  status = execute_phase(:exercise, context, @block) unless status
121
- status = execute_phase(:teardown, context, and_teardown) unless (status || !and_teardown)
121
+ status = execute_phase(:teardown, context, and_teardown.map { |t| [nil, t] }) unless (status || !and_teardown)
122
122
  status ||= Status.new(self, :success, context)
123
123
  end
124
124
 
@@ -138,7 +138,7 @@ module BareTest
138
138
 
139
139
  begin
140
140
  if code.is_a?(Array) then
141
- code.each do |block| context.instance_eval(&block) end
141
+ code.each do |args, block| context.instance_exec(*args, &block) end
142
142
  else
143
143
  unless context.instance_eval(&code)
144
144
  failure_reason = "Assertion failed"
@@ -74,11 +74,22 @@ module BareTest
74
74
  'lib' => %w[test/helper/suite test/suite],
75
75
  'rake' => %w[test/helper/suite test/suite],
76
76
  }
77
+ baretest_version = BareTest::VERSION.to_a.first(3).join('.').inspect
78
+ ruby_version = RUBY_VERSION.inspect
77
79
  files = {
78
80
  'test/setup.rb' => <<-END_OF_SETUP.gsub(/^ {10}/, '')
79
- BareTest.require_ruby #{RUBY_VERSION.inspect}
80
- BareTest.require_baretest #{BareTest::VERSION.to_a.first(3).join('.').inspect}
81
- $LOAD_PATH.unshift(File.expand_path("\#{__FILE__}/../../lib")) # Add PROJECT/lib to $LOAD_PATH
81
+ # Add PROJECT/lib to $LOAD_PATH
82
+ $LOAD_PATH.unshift(File.expand_path("\#{__FILE__}/../../lib"))
83
+
84
+ # Ensure baretest is required
85
+ require 'baretest'
86
+
87
+ # Some defaults on BareTest (see Kernel#BareTest)
88
+ BareTest do
89
+ require_baretest #{baretest_version} # minimum baretest version to run these tests
90
+ require_ruby #{ruby_version} # minimum ruby version to run these tests
91
+ use :support # Use :support in all suites
92
+ end
82
93
  END_OF_SETUP
83
94
  }
84
95
 
data/lib/baretest/run.rb CHANGED
@@ -200,7 +200,7 @@ module BareTest
200
200
  # Invoked once for every variation of an assertion.
201
201
  # Gets the assertion to run as single argument.
202
202
  def run_test(assertion, setup)
203
- rv = assertion.execute(setup.map { |s| s.block }, assertion.suite.ancestry_teardown)
203
+ rv = assertion.execute(setup, assertion.suite.ancestry_teardown)
204
204
  @count[:test] += 1
205
205
  @count[rv.status] += 1
206
206
 
@@ -241,7 +241,7 @@ module BareTest
241
241
  # Get an assertions' interpolated description for a given Array of Setup
242
242
  # instances.
243
243
  # See Assertion#interpolated_description
244
- def interpolated_description(assertion, setup)
244
+ def interpolated_description(assertion, setups)
245
245
  setups = setups ? setups.select { |s| s.component } : []
246
246
  substitutes = {}
247
247
  setups.each do |setup| substitutes[setup.component] = setup.substitute end
@@ -21,7 +21,7 @@ module BareTest
21
21
  TINY = 0
22
22
 
23
23
  # Prerelease number - nil for release versions
24
- PRERELEASE = 1
24
+ PRERELEASE = 2
25
25
 
26
26
  # The version as a string
27
27
  STRING = %{#{MAJOR}.#{MINOR||0}.#{TINY||0}#{".pre#{PRERELEASE}" if PRERELEASE}}
data/lib/baretest.rb CHANGED
@@ -19,6 +19,16 @@ require 'ruby/kernel'
19
19
 
20
20
 
21
21
 
22
+ module Kernel
23
+ # Execute a piece of code in the context of BareTest
24
+ def BareTest(&block)
25
+ BareTest.instance_eval(&block)
26
+ end
27
+ module_function :BareTest
28
+ end
29
+
30
+
31
+
22
32
  module BareTest
23
33
  # A lookup table to test which of two states is more important
24
34
  # (MoreImportantStatus[[a,b]] # => a or b)
data/test/setup.rb CHANGED
@@ -1,5 +1,12 @@
1
- BareTest.require_baretest "0.4"
2
- BareTest.require_ruby "1.8.6"
3
-
1
+ # Add PROJECT/lib to $LOAD_PATH
4
2
  $LOAD_PATH.unshift(File.expand_path("#{__FILE__}/../../lib"))
3
+
4
+ # Ensure baretest is required
5
5
  require 'baretest'
6
+
7
+ # Some defaults on BareTest (see Kernel#BareTest)
8
+ BareTest do
9
+ require_baretest "0.4" # minimum baretest version to run these tests
10
+ require_ruby "1.8.6" # minimum ruby version to run these tests
11
+ use :support # Use :support in all suites
12
+ end
@@ -245,6 +245,101 @@ BareTest.suite "BareTest" do
245
245
  end
246
246
  end
247
247
 
248
+ suite "#run_test_variants" do
249
+ suite "With a suite with no setup" do
250
+ setup do
251
+ @suite = ::BareTest::Suite.new
252
+ @assertion = ::BareTest::Assertion.new @suite, "test" do true end
253
+ @run = ::BareTest::Run.new(::BareTest::Suite.new)
254
+ end
255
+
256
+ assert "Invokes run_test with the assertion once" do
257
+ invoked = []
258
+ (class <<@run; self; end).send :define_method, :run_test do |assertion, setup|
259
+ invoked << [assertion, setup]
260
+ ::BareTest::Status.new(assertion, :success)
261
+ end
262
+ @run.run_test_variants(@assertion)
263
+
264
+ equal_unordered([[@assertion, []]], invoked)
265
+ end
266
+ end
267
+
268
+ suite "With a suite with a static setup" do
269
+ setup do
270
+ @suite = ::BareTest::Suite.new do
271
+ setup do "nothing" end
272
+ end
273
+ @assertion = ::BareTest::Assertion.new @suite, "test" do true end
274
+ @run = ::BareTest::Run.new(::BareTest::Suite.new)
275
+
276
+ @setups = @suite.instance_variable_get(:@setup)[nil]
277
+ end
278
+
279
+ assert "Invokes run_test with the assertion once" do
280
+ invoked = []
281
+ (class <<@run; self; end).send :define_method, :run_test do |assertion, setup|
282
+ invoked << [assertion, setup]
283
+ ::BareTest::Status.new(assertion, :success)
284
+ end
285
+ @run.run_test_variants(@assertion)
286
+
287
+ equal_unordered([[@assertion, @setups]], invoked)
288
+ end
289
+ end
290
+
291
+ suite "With a suite with a dynamic setup" do
292
+ setup do
293
+ @suite = ::BareTest::Suite.new do
294
+ setup :component_name do "nothing" end
295
+ end
296
+ @assertion = ::BareTest::Assertion.new @suite, "test" do true end
297
+ @run = ::BareTest::Run.new(::BareTest::Suite.new)
298
+
299
+ @setups = @suite.instance_variable_get(:@setup)[:component_name]
300
+ end
301
+
302
+ assert "Invokes run_test with the assertion once" do
303
+ invoked = []
304
+ (class <<@run; self; end).send :define_method, :run_test do |assertion, setup|
305
+ invoked << [assertion, setup]
306
+ ::BareTest::Status.new(assertion, :success)
307
+ end
308
+ @run.run_test_variants(@assertion)
309
+
310
+ equal_unordered([[@assertion, @setups]], invoked)
311
+ end
312
+ end
313
+
314
+ suite "With a suite with multiple dynamic setups using hash notation" do
315
+ setup do
316
+ @suite = ::BareTest::Suite.new do
317
+ setup :component_name, {:a => 1, :b => 2, :c => 3} do "nothing" end
318
+ end
319
+ @assertion = ::BareTest::Assertion.new @suite, "test" do true end
320
+ @run = ::BareTest::Run.new(::BareTest::Suite.new)
321
+
322
+ @setups = @suite.instance_variable_get(:@setup)[:component_name]
323
+ end
324
+
325
+ assert "Invokes run_test with the assertion 3 times, with the corresponding setup" do
326
+ actual = []
327
+ (class <<@run; self; end).send :define_method, :run_test do |assertion, setup|
328
+ actual << [assertion, setup]
329
+ ::BareTest::Status.new(assertion, :success)
330
+ end
331
+ @run.run_test_variants(@assertion)
332
+ expected = @setups.map { |setup| [@assertion,[setup]] }
333
+
334
+ equal_unordered(expected, actual)
335
+ end
336
+ end
337
+ end
338
+
339
+ suite "#interpolated_description" do
340
+
341
+ end
342
+
248
343
  suite "#run_test" do
249
344
  assert "Runs the given test" do
250
345
  # should implement this with a mock, expecting #execute to be called
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baretest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre1
4
+ version: 0.4.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Rusterholz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-15 00:00:00 +01:00
12
+ date: 2010-02-17 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -118,7 +118,7 @@ rdoc_options:
118
118
  - --tab-width
119
119
  - "2"
120
120
  - -t
121
- - baretest-0.4.0.pre1
121
+ - baretest-0.4.0.pre2
122
122
  require_paths:
123
123
  - lib
124
124
  required_ruby_version: !ruby/object:Gem::Requirement