francois-context 0.5.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestContext < Test::Unit::TestCase
4
+ def test_can_write_tests_without_context
5
+ assert true
6
+ end
7
+
8
+ def test_context_aliases
9
+ [:context, :contexts, :describe, :describes, :group, :specify, :specifies].each do |method_alias|
10
+ assert self.class.respond_to?(method_alias)
11
+ end
12
+ end
13
+
14
+ context "A new context" do
15
+ context "when not nested" do
16
+ before do
17
+ @context = Class.new(Test::Unit::TestCase).context("When testing") do
18
+ def test_this_thing
19
+ true
20
+ end
21
+ end
22
+ end
23
+
24
+ it "should set the context name" do
25
+ assert_equal "When testing", @context.context_name
26
+ end
27
+
28
+ it "should be a Test::Unit::TestCase" do
29
+ assert @context.ancestors.include?(Test::Unit::TestCase)
30
+ end
31
+ end
32
+
33
+ context "when nested" do
34
+ before do
35
+ @context = self.class.context("and we're testing") do
36
+ def self.nested
37
+ @nested
38
+ end
39
+
40
+ @nested = context "should be nested" do
41
+ def test_this_thing
42
+ true
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ it "should set a nested context's name" do
49
+ assert_equal "A new context when nested and we're testing should be nested", @context.nested.context_name
50
+ end
51
+
52
+ it "should also be a Test::Unit::TestCase" do
53
+ assert @context.nested.ancestors.include?(Test::Unit::TestCase)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestCoreExt < Test::Unit::TestCase
4
+ context "A string" do
5
+ it "should be converted to method name" do
6
+ assert :this_is_fun, "this is fun".to_method_name
7
+ end
8
+
9
+ it "should be downcased when converted" do
10
+ assert :this_is_a_blast, "THIS is A BlASt".to_method_name
11
+ end
12
+
13
+ it "should change spaces to _" do
14
+ assert :this_has_been_great, "This has been great".to_method_name
15
+ end
16
+
17
+ it "should change dangerous punctuation to _" do
18
+ assert :no__really__this_was__good_, "No, really; this was #good!".to_method_name
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/context'
@@ -0,0 +1,164 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestLifecycle < Test::Unit::TestCase
4
+ before do
5
+ @inherited_before_each_var = 1
6
+ end
7
+
8
+ before do
9
+ @inherited_before_each_var = 2
10
+ @inherited_before_each_var_2 = 1
11
+ end
12
+
13
+ after do
14
+ @inherited_after_each_var = 1
15
+ end
16
+
17
+ before :all do
18
+ @inherited_before_all_var = 1
19
+ end
20
+
21
+ after :all do
22
+ @inherited_after_all_var = 1
23
+ end
24
+
25
+ sample_test = context "lifecycle" do
26
+ attr_reader :inherited_before_each_var, :inherited_before_each_var_2, :inherited_after_each_var,
27
+ :after_each_var, :inherited_before_all_var, :inherited_after_all_var, :before_all_var, :after_all_var,
28
+ :superclass_before_each_var, :superclass_after_each_var, :superclass_before_all_var, :superclass_after_all_var, :one, :two
29
+
30
+ before do
31
+ @inherited_before_each_var = 3
32
+ end
33
+
34
+ after do
35
+ @after_each_var = 1
36
+ end
37
+
38
+ before :all do
39
+ @before_all_var = 1
40
+ end
41
+
42
+ after :all do
43
+ @after_all_var = 1
44
+ end
45
+
46
+ test "foo" do
47
+ end
48
+ end
49
+
50
+ before do
51
+ @superclass_before_each_var = 1
52
+ end
53
+
54
+ after do
55
+ @superclass_after_each_var = 1
56
+ end
57
+
58
+ before :all do
59
+ @superclass_before_all_var = 1
60
+ end
61
+
62
+ after :all do
63
+ @superclass_after_all_var = 1
64
+ end
65
+
66
+ context "With before/after :each blocks" do
67
+ before do
68
+ @result = Test::Unit::TestResult.new
69
+ @test = sample_test.new("test_lifecycle_foo")
70
+ @test.run(@result) { |inherited_after_each_var, v| }
71
+ end
72
+
73
+ it "it runs superclass before callbacks in order" do
74
+ assert_equal 1, @test.superclass_before_each_var
75
+ end
76
+
77
+ it "it runs inherited before callbacks in order" do
78
+ assert_equal 3, @test.inherited_before_each_var
79
+ end
80
+
81
+ it "it runs before callbacks in order" do
82
+ assert_equal 1, @test.inherited_before_each_var_2
83
+ end
84
+
85
+ it "it runs superclass after callbacks" do
86
+ assert_equal 1, @test.superclass_after_each_var
87
+ end
88
+
89
+ it "it runs inherited after callbacks" do
90
+ assert_equal 1, @test.inherited_after_each_var
91
+ end
92
+
93
+ it "it runs after callbacks" do
94
+ assert_equal 1, @test.after_each_var
95
+ end
96
+ end
97
+
98
+ context "With before/after :all blocks" do
99
+ before do
100
+ @result = Test::Unit::TestResult.new
101
+ @suite = sample_test.suite
102
+ @suite.run(@result) { |inherited_after_each_var, v| }
103
+ @test = @suite.tests.first
104
+ end
105
+
106
+ it "it runs superclass before callbacks in order" do
107
+ assert_equal 1, @test.superclass_before_all_var
108
+ end
109
+
110
+ it "it runs inherited before callbacks in order" do
111
+ assert_equal 1, @test.inherited_before_all_var
112
+ end
113
+
114
+ it "it runs before callbacks in order" do
115
+ assert_equal 1, @test.before_all_var
116
+ end
117
+
118
+ it "it runs superclass after callbacks" do
119
+ assert_equal 1, @test.superclass_after_all_var
120
+ end
121
+
122
+ it "it runs inherited after callbacks" do
123
+ assert_equal 1, @test.inherited_after_all_var
124
+ end
125
+
126
+ it "it runs after callbacks" do
127
+ assert_equal 1, @test.after_all_var
128
+ end
129
+ end
130
+
131
+ # Test that we aren't stomping on defined seutp method
132
+ context "With setup/teardown methods" do
133
+ before do
134
+ @result = Test::Unit::TestResult.new
135
+ @test = sample_test.new("test_lifecycle_foo")
136
+
137
+ @test.class.setup do
138
+ @one = 1
139
+ end
140
+
141
+ @test.class.teardown do
142
+ @two = 10
143
+ end
144
+
145
+ @test.run(@result) { |inherited_after_each_var, v| }
146
+ end
147
+
148
+ it "runs setup method block a la Shoulda" do
149
+ assert_equal 1, @test.one
150
+ end
151
+
152
+ it "runs setup method block and regular callbacks" do
153
+ assert_equal 3, @test.inherited_before_each_var
154
+ end
155
+
156
+ it "runs teardown method block a la Shoulda" do
157
+ assert_equal 10, @test.two
158
+ end
159
+
160
+ it "runs teardown method block and regular callbacks" do
161
+ assert_equal 1, @test.after_each_var
162
+ end
163
+ end
164
+ end
data/test/test_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestTest < Test::Unit::TestCase
4
+ def test_test_aliases
5
+ [:test, :it, :should, :tests].each do |method_alias|
6
+ assert self.class.respond_to?(method_alias)
7
+ end
8
+ end
9
+
10
+ context "A test block" do
11
+ it "should create a test_xxx method" do
12
+ self.class.test("should create a test method") { true }
13
+
14
+ assert self.respond_to?(:test_a_test_block_should_create_a_test_method)
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: francois-context
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy McAnally
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: If you've ever wanted contexts in your Test::Unit tests, then context is for you. Your tests will be easier to read and write without all the magic and extra code smell!
17
+ email: jeremy@entp.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - Manifest.txt
25
+ - README.rdoc
26
+ files:
27
+ - README.rdoc
28
+ - Rakefile
29
+ - context.gemspec
30
+ - History.txt
31
+ - License.txt
32
+ - Manifest.txt
33
+ - PostInstall.txt
34
+ - config/hoe.rb
35
+ - config/requirements.rb
36
+ - lib/context.rb
37
+ - lib/context/version.rb
38
+ - lib/context/lifecycle.rb
39
+ - lib/context/suite.rb
40
+ - lib/context/context.rb
41
+ - lib/context/shared_behavior.rb
42
+ - lib/context/test.rb
43
+ - lib/context/core_ext/string.rb
44
+ - lib/context/core_ext/rails_hacks.rb
45
+ - setup.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/jeremymcanally/context
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Contexts and DSL sugar for your tests
73
+ test_files:
74
+ - test/test_context.rb
75
+ - test/test_core_ext.rb
76
+ - test/test_lifecycle.rb
77
+ - test/test_test.rb
78
+ - test/test_helper.rb