nutrasuite 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,7 @@ Nutrasuite is all about contexts. Write your tests like so:
32
32
  require 'nutrasuite'
33
33
  class SomeTest < MiniTest::Unit::TestCase
34
34
  a "newly instantiated test object" do
35
- setup do
35
+ before do
36
36
  some_setup_stuff
37
37
  end
38
38
 
@@ -40,19 +40,19 @@ Nutrasuite is all about contexts. Write your tests like so:
40
40
  assert true
41
41
  end
42
42
 
43
- teardown do
43
+ after do
44
44
  some_teardown_stuff
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
49
  All of your other minitest stuff should work normally. Context
50
- setup/teardown is executed once for each test, so the randomization built into
50
+ before/after blocks are executed once for each test, so the randomization built into
51
51
  minitest will still work as you'd expect.
52
52
 
53
- `a`, `an`, `and`, `the`, and `that` all define contexts, so you can build
54
- readable sentences like "_a_ user _that_ has an expired password _and_ a bad email
55
- address" or "_the_ singleton."
53
+ `a`, `an`, `and_also`, `the`, and `that` all define contexts, so you can build
54
+ readable sentences like "_a_ user _that_ has an expired password _and_also_ a bad
55
+ email address" or "_the_ singleton."
56
56
 
57
57
  `it` defines tests; `it_eventually` defines tests that are to be skipped.
58
58
 
@@ -20,10 +20,10 @@ module Nutrasuite
20
20
  # ...tests...
21
21
  # end
22
22
  #
23
- ["a", "an", "and", "that", "the"].each do |article|
23
+ ["a", "an", "and_also", "that", "the"].each do |article|
24
24
  eval <<-HERE
25
25
  def #{article}(name, &block)
26
- name = "#{article} " << name
26
+ name = "#{article.gsub("_"," ")} " << name
27
27
  Context.push(name, &block)
28
28
  end
29
29
  HERE
@@ -32,47 +32,13 @@ module Nutrasuite
32
32
  # Public: use before to declare steps that need to be run before every test
33
33
  # in a context.
34
34
  def before(&block)
35
- if Context.current_context?
36
- Context.current_context.setups << block
37
- else
38
- warn "Not in a context"
39
- end
40
- end
41
-
42
- # Deprecated: As much as I'd like to use setup and teardown, they screw up
43
- # at times with ActiveSupport test cases. Better to use before and after.
44
- #
45
- # This method will be removed by 0.3.0. Please adjust your tests
46
- # accordingly.
47
- def setup(&block)
48
- if Context.current_context?
49
- Context.current_context.setups << block
50
- else
51
- warn "Not in a context"
52
- end
35
+ Context.current_context.setups << block
53
36
  end
54
37
 
55
38
  # Public: use after to declare steps that need to be run after every test in
56
39
  # a context.
57
40
  def after(&block)
58
- if Context.current_context?
59
- Context.current_context.teardowns << block
60
- else
61
- warn "Not in a context"
62
- end
63
- end
64
-
65
- # Deprecated: As mich as I'd like to use setup and teardown, they screw up
66
- # at times with ActiveSupport test cases. Better to use before and after.
67
- #
68
- # This method will be removed by 0.3.0. Please adjust your tests
69
- # accordingly.
70
- def teardown(&block)
71
- if Context.current_context?
72
- Context.current_context.teardowns << block
73
- else
74
- warn "Not in a context"
75
- end
41
+ Context.current_context.teardowns << block
76
42
  end
77
43
 
78
44
  # Public: defines a test to be executed. Will run any setup blocks on the
@@ -142,14 +108,6 @@ module Nutrasuite
142
108
  end
143
109
  end
144
110
  end
145
-
146
- # Internal: warn simply outputs a warning message for the user if they
147
- # appear to be using Nutrasuite incorrectly.
148
- #
149
- def warn(message)
150
- puts " * Warning: #{message}"
151
- end
152
-
153
111
  end
154
112
 
155
113
  # Internal: The Context class represents each context that can go on the
@@ -202,7 +160,9 @@ module Nutrasuite
202
160
  def self.build_test_name(name="")
203
161
  full_name = "test "
204
162
  context_stack.each do |context|
205
- full_name << context.name << " "
163
+ unless context.name.nil?
164
+ full_name << context.name << " "
165
+ end
206
166
  end
207
167
  full_name << name
208
168
  end
@@ -228,7 +188,7 @@ module Nutrasuite
228
188
  #
229
189
  # Returns: an Array representing the context stack.
230
190
  def self.context_stack
231
- @context_stack ||= []
191
+ @context_stack ||= [Context.new(nil)]
232
192
  end
233
193
 
234
194
  # Internal: get the current context.
@@ -238,14 +198,6 @@ module Nutrasuite
238
198
  def self.current_context
239
199
  context_stack.last
240
200
  end
241
-
242
- # Internal: determine whether there is currently a context active.
243
- #
244
- # Returns: true if there is at least one context on the stack, false
245
- # otherwise.
246
- def self.current_context?
247
- !context_stack.empty?
248
- end
249
201
  end
250
202
  end
251
203
 
@@ -1,3 +1,3 @@
1
1
  module Nutrasuite
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
+ s.add_development_dependency "activesupport"
22
23
  # s.add_development_dependency "rspec"
23
24
  # s.add_runtime_dependency "rest-client"
24
25
  end
@@ -1 +1,2 @@
1
1
  require 'nutrasuite'
2
+ require 'active_support'
@@ -0,0 +1,114 @@
1
+ require 'test_helper'
2
+
3
+ # ActiveSupport does funny stuff with its test cases, so we have to be
4
+ # especially sure that nutrasuite plays nicely with it (and vice versa).
5
+ class ActivesupportTest < ActiveSupport::TestCase
6
+
7
+ before do
8
+ @root = "test"
9
+ end
10
+
11
+ it "allows tests outside of any context" do
12
+ assert true
13
+ end
14
+
15
+ it "runs the before blocks at the root level" do
16
+ assert_equal "test", @root
17
+ end
18
+
19
+ it_eventually "allows tests to be skipped outside of any context" do
20
+ raise "This exception should never be thrown."
21
+ end
22
+
23
+ it "names tests correctly" do
24
+ assert_equal "test some name", Nutrasuite::Context.build_test_name("some name")
25
+ end
26
+
27
+ a "Context" do
28
+ before do
29
+ @a = 5
30
+ end
31
+
32
+ it "runs befores before tests" do
33
+ assert_equal @a, 5
34
+ assert_equal @root, "test"
35
+ end
36
+
37
+ it_eventually "passes its name onto its test" do
38
+ # TODO: figure out how to test this
39
+ end
40
+
41
+ it "doesn't run befores from nested contexts" do
42
+ assert_equal nil, @b
43
+ end
44
+
45
+ that "has a nested Context" do
46
+ before do
47
+ @b = 10
48
+ end
49
+
50
+ it "runs both befores" do
51
+ assert_equal @a, 5
52
+ assert_equal @b, 10
53
+ end
54
+ end
55
+
56
+ that "has a nested Context with multiple befores" do
57
+ before do
58
+ @b = 6
59
+ end
60
+
61
+ before do
62
+ @c = 7
63
+ @b = @b + 1
64
+ end
65
+
66
+ it "runs all befores in order" do
67
+ assert_equal @b, 7
68
+ assert_equal @b, @c
69
+ end
70
+ end
71
+ end
72
+
73
+ a "Second context" do
74
+ before do
75
+ @b = true
76
+ end
77
+
78
+ it "isn't affected by befores from other contexts" do
79
+ assert_equal true, @b
80
+ assert @a.nil?
81
+ end
82
+ end
83
+
84
+ the "'the' context" do
85
+ it "works" do
86
+ assert true
87
+ end
88
+ end
89
+
90
+ an "'an' context" do
91
+ it "works" do
92
+ assert true
93
+ end
94
+ end
95
+
96
+ and_also "the 'and_also' context" do
97
+ it "works" do
98
+ assert true
99
+ end
100
+ end
101
+
102
+ a "'a' context" do
103
+ it "works" do
104
+ assert true
105
+ end
106
+ end
107
+
108
+ that "'that' context" do
109
+ it "works" do
110
+ assert true
111
+ end
112
+ end
113
+ end
114
+
@@ -1,11 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ContextsTest < Test::Unit::TestCase
4
+ before do
5
+ @root = "test"
6
+ end
4
7
 
5
8
  it "allows tests outside of any context" do
6
9
  assert true
7
10
  end
8
11
 
12
+ it "runs the before blocks at the root level" do
13
+ assert_equal "test", @root
14
+ end
15
+
9
16
  it_eventually "allows tests to be skipped outside of any context" do
10
17
  raise "This exception should never be thrown."
11
18
  end
@@ -21,6 +28,7 @@ class ContextsTest < Test::Unit::TestCase
21
28
 
22
29
  it "runs befores before tests" do
23
30
  assert_equal @a, 5
31
+ assert_equal @root, "test"
24
32
  end
25
33
 
26
34
  it_eventually "passes its name onto its tests" do
@@ -72,19 +80,19 @@ class ContextsTest < Test::Unit::TestCase
72
80
  end
73
81
  end
74
82
 
75
- the "'and' context" do
83
+ and_also "'and_also' context" do
76
84
  it "works" do
77
85
  assert true
78
86
  end
79
87
  end
80
88
 
81
- the "'an' context" do
89
+ an "'an' context" do
82
90
  it "works" do
83
91
  assert true
84
92
  end
85
93
  end
86
94
 
87
- the "'that' context" do
95
+ that "'that' context" do
88
96
  it "works" do
89
97
  assert true
90
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutrasuite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,19 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-04 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2012-03-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: &70199395886180 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70199395886180
15
26
  description: Nutrasuite is a low-calorie syntax sweetener for minitest
16
27
  email:
17
28
  - tommy.morgan@gmail.com
@@ -29,6 +40,7 @@ files:
29
40
  - lib/nutrasuite/version.rb
30
41
  - nutrasuite.gemspec
31
42
  - test/test_helper.rb
43
+ - test/unit/activesupport_test.rb
32
44
  - test/unit/contexts_test.rb
33
45
  homepage: http://github.com/duwanis/nutrasuite
34
46
  licenses: []
@@ -56,5 +68,6 @@ specification_version: 3
56
68
  summary: Nutrasuite is a low-calorie syntax sweetener for minitest
57
69
  test_files:
58
70
  - test/test_helper.rb
71
+ - test/unit/activesupport_test.rb
59
72
  - test/unit/contexts_test.rb
60
73
  has_rdoc: