test-belt 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /pkg/
2
+ /doc/
3
+ /coverage/
4
+ *.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in i-env.gemspec
4
+ gemspec
data/README.rdoc CHANGED
@@ -22,7 +22,7 @@ TestBelt only impacts your testing environment or setup and is designed only for
22
22
  # other gem dependencies ...
23
23
 
24
24
  group :test do
25
- gem 'test-belt'
25
+ gem 'test-belt', :require => 'test_belt'
26
26
 
27
27
  # other testing gem dependencies ...
28
28
  end
@@ -64,6 +64,22 @@ I've added some contexts callbacks in addition to the setup/teardown callbacks S
64
64
  * suite_started / on_suite_started - runs one time before any of the tests across the entire test suite are run
65
65
  * suite_finished / on_suite_finished - runs one time after all of the tests across the entire test suite are run
66
66
 
67
+ === Test::Unit 'skip' directive
68
+ Test::Unit already provides a 'flunk' directive that will fail the current test. I've added a 'skip' directive that will skip the test when running the suite. I use it to ignore certain tests while I focus on others. Skipping while using LeftRight allows me to ignore the test but not forget about it when looking at my test results.
69
+
70
+ class TestCaseTest < Test::Unit::TestCase
71
+
72
+ context "Something" do
73
+ should "be something awesome" do
74
+ skip
75
+ # anything after the 'skip' directive will not be executed
76
+ # => use skip(false) to not halt execution
77
+ assert something_is_in_fact_awesome
78
+ end
79
+ end
80
+
81
+ end
82
+
67
83
  == Generated Rake tasks
68
84
  === For running tests
69
85
  TestBelt can provide an automatic set of rake tasks for testing subsets of your code base. These tasks are defined based on the structure of your test files. To use this first add this to your Rakefile:
data/Rakefile CHANGED
@@ -1,37 +1,7 @@
1
- require 'rubygems'
2
- require 'rake/gempackagetask'
3
- require 'lib/test_belt/version'
4
-
5
- spec = Gem::Specification.new do |s|
6
- s.name = 'test-belt'
7
- s.version = TestBelt::Version.to_s
8
- s.has_rdoc = true
9
- s.extra_rdoc_files = %w(README.rdoc)
10
- s.rdoc_options = %w(--main README.rdoc)
11
- s.summary = "A gem for using testing tools I like - my Ruby testing toolbelt."
12
- s.author = 'Kelly Redding'
13
- s.email = 'kelly@kelredd.com'
14
- s.homepage = 'http://github.com/kelredd/test-belt'
15
- s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
16
-
17
- s.add_dependency("shoulda", ["~> 2.11"])
18
- s.add_dependency("leftright", ["~> 0.9.0"])
19
- s.add_dependency("kelredd-useful", ["~> 0.4.0"])
20
- end
21
-
22
- Rake::GemPackageTask.new(spec) do |pkg|
23
- pkg.gem_spec = spec
24
- end
25
-
26
- desc 'Generate the gemspec for this gem'
27
- task :gemspec do
28
- file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
29
- File.open(file, 'w') {|f| f << spec.to_ruby }
30
- puts "Created gemspec: #{file}"
31
- end
32
-
33
- task :default => :gem
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
34
3
 
35
4
  require 'lib/test_belt/rake_tasks'
36
5
  TestBelt::RakeTasks.for :test
37
6
 
7
+ task :default => :build
@@ -4,4 +4,5 @@ module TestBelt; end
4
4
  module TestBelt::TestUnit; end
5
5
 
6
6
  require 'test_belt/test_unit/context'
7
+ require 'test_belt/test_unit/test_case'
7
8
 
@@ -0,0 +1,26 @@
1
+ require 'test/unit'
2
+
3
+ module TestBelt::TestUnit
4
+ class TestSkipped < Exception; end
5
+ end
6
+
7
+ module Test::Unit
8
+ class TestCase
9
+
10
+ alias_method(:orig_add_error, :add_error)
11
+ def add_error(*args, &block)
12
+ unless args.first.kind_of?(::TestBelt::TestUnit::TestSkipped)
13
+ orig_add_error *args, &block
14
+ end
15
+ end
16
+
17
+ def skip(halt_test=true)
18
+ if defined? ::LeftRight
19
+ ::LeftRight.state.skip = true
20
+ ::LeftRight.state.skipped_count += 1
21
+ end
22
+ raise ::TestBelt::TestUnit::TestSkipped if halt_test
23
+ end
24
+
25
+ end
26
+ end
@@ -1,13 +1,3 @@
1
1
  module TestBelt
2
- module Version
3
-
4
- MAJOR = 0
5
- MINOR = 1
6
- TINY = 2
7
-
8
- def self.to_s # :nodoc:
9
- [MAJOR, MINOR, TINY].join('.')
10
- end
11
-
12
- end
2
+ VERSION = "0.2.0"
13
3
  end
data/test-belt.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "test_belt/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "test-belt"
7
+ s.version = TestBelt::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kelly D. Redding"]
10
+ s.email = ["kelly@kelredd.com"]
11
+ s.homepage = "http://github.com/kelredd/test-belt"
12
+ s.summary = %q{A gem for using testing tools I like - my Ruby testing toolbelt.}
13
+ s.description = %q{This is my Ruby testing "tool belt". It packages up the most common testing tools and paradigms I use. It is opinionated and custom to how I like to test.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency("bundler", ["~> 1.0"])
21
+
22
+ s.add_dependency("shoulda", ["~> 2.11"])
23
+ s.add_dependency("leftright", ["~> 0.9.0"])
24
+ s.add_dependency("kelredd-useful", ["~> 0.4.0"])
25
+ end
data/test/env.rb ADDED
@@ -0,0 +1,9 @@
1
+ # Add test and lib paths to the $LOAD_PATH
2
+ [ File.dirname(__FILE__),
3
+ File.join(File.dirname(__FILE__), '..', 'lib')
4
+ ].each do |path|
5
+ full_path = File.expand_path(path)
6
+ $LOAD_PATH.unshift(full_path) unless $LOAD_PATH.include?(full_path)
7
+ end
8
+
9
+ require 'test_belt'
@@ -0,0 +1,25 @@
1
+ class Thing
2
+ attr_reader :reader1, :reader2, :reader3
3
+ attr_writer :writer1, :writer2, :writer3
4
+ attr_accessor :accessor1, :accessor2, :accessor3
5
+
6
+ def initialize
7
+ @reader1, @reader2, @reader3 = [1, 2, 3]
8
+ @writer1, @writer2, @writer3 = [1, 2, 3]
9
+ @accessor1, @accessor2, @accessor3 = [1, 2, 3]
10
+ end
11
+
12
+ def an_instance_meth
13
+ "instance"
14
+ end
15
+ alias_method :instance1, :an_instance_meth
16
+ alias_method :instance2, :an_instance_meth
17
+
18
+ class << self
19
+ def a_class_meth
20
+ "class"
21
+ end
22
+ alias_method :class1, :a_class_meth
23
+ alias_method :class2, :a_class_meth
24
+ end
25
+ end
data/test/helper.rb ADDED
@@ -0,0 +1 @@
1
+ require 'test/env'
@@ -0,0 +1,29 @@
1
+ require "test/helper"
2
+ require 'lib/test_belt/rake_tasks'
3
+
4
+ module TestBelt
5
+ class RakeTasksTest < Test::Unit::TestCase
6
+
7
+ context "TestBelt Rake Tasks" do
8
+
9
+ context "TestTask" do
10
+ subject { RakeTasks::TestTask.new }
11
+
12
+ should_have_accessors :name, :description, :test_files
13
+ should_have_instance_method :to_task
14
+
15
+ context "with test files" do
16
+ setup do
17
+ subject.test_files = ["file1.rb", "file2.rb"]
18
+ end
19
+
20
+ should "return a list of it's test_files" do
21
+ assert_equal "\"file1.rb\" \"file2.rb\"", subject.file_list
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require "test/helper"
2
+ require "test/fixtures/shoulda_macros/thing"
3
+
4
+ class ClassesTest < Test::Unit::TestCase
5
+
6
+ context "TestBelt Shoulda Macros for classes" do
7
+ subject { Thing.new }
8
+
9
+ should_have_instance_method :an_instance_meth
10
+ should_have_instance_methods :instance1, :instance2
11
+ should_have_class_method :a_class_meth
12
+ should_have_class_methods :class1, :class2
13
+ should_have_readers :reader1, :reader2
14
+ should_have_reader :reader3
15
+ should_have_writers :writer1, :writer2
16
+ should_have_writer :writer3
17
+ should_have_accessors :accessor1, :accessor2
18
+ should_have_accessor :accessor3
19
+ end
20
+
21
+ end
@@ -0,0 +1,28 @@
1
+ require "test/helper"
2
+ require "test/fixtures/shoulda_macros/thing"
3
+
4
+ module TestBelt::ShouldaMacros
5
+ class ContextTest < Test::Unit::TestCase
6
+
7
+ context "TestBelt Shoulda Macros for context" do
8
+ setup do
9
+ @thing = Thing.new
10
+ end
11
+
12
+ context "callbacks that setup/teardown each test" do
13
+ before do
14
+ @thing.accessor1 = "before"
15
+ end
16
+ after do
17
+ assert_equal 'after', @thing.accessor1, "the accessor was not set correctly in the after block"
18
+ end
19
+
20
+ should "run using before/after blocks" do
21
+ assert_equal 'before', @thing.accessor1, "the accessor was not set correctly in the before block"
22
+ @thing.accessor1 = "after"
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ require "test/helper"
2
+
3
+ module TestBelt::ShouldaMacros
4
+ class FilesTest < Test::Unit::TestCase
5
+
6
+ context "TestBelt Shoulda Macros for files" do
7
+
8
+ # should require a root path
9
+ setup do
10
+ @root_path = File.expand_path(File.dirname(__FILE__))
11
+ end
12
+
13
+ # should provide these macros
14
+ should "provide a set of macros" do
15
+ assert self.class.respond_to?(:should_have_directories), "no :should_have_directories macro"
16
+ assert self.class.respond_to?(:should_have_directory), "no :should_have_directory macro"
17
+ assert self.class.respond_to?(:should_have_files), "no :should_have_files macro"
18
+ assert self.class.respond_to?(:should_have_file), "no :should_have_file macro"
19
+ end
20
+
21
+ # should find the @root_path directory
22
+ should_have_directories
23
+
24
+ #should find files in the @root_path directory
25
+ should_have_files 'files_test.rb'
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,65 @@
1
+ require "test/helper"
2
+
3
+ module TestBelt::TestUnit
4
+
5
+ class ContextTest < Test::Unit::TestCase
6
+
7
+ suite_started do
8
+ if @suite_started
9
+ @suite_started_fail = true
10
+ end
11
+ @suite_started = true
12
+ end
13
+
14
+ suite_finished do
15
+ raise "suite_started did not run once" unless @suite_started
16
+ raise "suite_started ran more than once" unless @suite_started_fail.nil?
17
+ end
18
+
19
+ on_suite_started do
20
+ if @on_suite_started
21
+ @on_suite_started_fail = true
22
+ end
23
+ @on_suite_started = true
24
+ end
25
+
26
+ on_suite_finished do
27
+ raise "on_suite_started did not run once" unless @on_suite_started
28
+ raise "on_suite_started ran more than once" unless @on_suite_started_fail.nil?
29
+ end
30
+
31
+ context "TestBelt Test::Unit Context" do
32
+ setup_once do
33
+ if @setup_once
34
+ @setup_once_fail = true
35
+ end
36
+ @setup_once = true
37
+ end
38
+
39
+ teardown_once do
40
+ raise "setup_once did not run once" unless @setup_once
41
+ raise "setup_once ran more than once" unless @setup_once_fail.nil?
42
+ end
43
+
44
+ before_once do
45
+ if @before_once
46
+ @before_once_fail = true
47
+ end
48
+ @before_once = true
49
+ end
50
+
51
+ after_once do
52
+ raise "before_once did not run once" unless @before_once
53
+ raise "before_once ran more than once" unless @before_once_fail.nil?
54
+ end
55
+
56
+ should "provide callbacks for suite starting and finishing" do
57
+ end
58
+
59
+ should "provide callbacks for testcase setup/teardown and before/after once" do
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,31 @@
1
+ require "test/helper"
2
+ require "test_belt/test_unit/runner"
3
+
4
+ module TestBelt::TestUnit
5
+
6
+ class RunnerTest < Test::Unit::TestCase
7
+
8
+ context "TestBelt Test::Unit" do
9
+
10
+ context "Runner" do
11
+ subject { Runner.new "something" }
12
+
13
+ should "be either a LeftRight runner or a Test::Unit Runner" do
14
+ assert subject.kind_of?(::LeftRight::Runner) || subject.kind_of?(::Test::Unit::UI::Console::TestRunner)
15
+ end
16
+
17
+ should_have_instance_method :started, :finished
18
+ end
19
+
20
+ context "AutoRunner" do
21
+ should "be overridden to use the TestBelt runner for it's runner" do
22
+ assert_nothing_raised do
23
+ ::Test::Unit::AutoRunner.new "something"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,30 @@
1
+ require "test/helper"
2
+ require "test_belt/test_unit/test_case"
3
+
4
+ module TestBelt::TestUnit
5
+
6
+ class TestCaseTest < Test::Unit::TestCase
7
+
8
+ context "TestBelt Test::Unit" do
9
+
10
+ context "TestCase" do
11
+ subject { nil }
12
+
13
+ should "provide a skip assertion that uses LeftRight's skipping logic" do
14
+ assert_respond_to self, :skip, 'no skip method for the test case'
15
+ prev_skipped_count = ::LeftRight.state.skipped_count if defined? ::LeftRight
16
+ skip(false)
17
+ if defined? ::LeftRight
18
+ assert ::LeftRight.state.skip, 'left right is not in skip state for this case'
19
+ assert_equal prev_skipped_count+1, ::LeftRight.state.skipped_count, 'LeftRight\'s skip count was not incremented'
20
+ ::LeftRight.state.skip = false
21
+ ::LeftRight.state.skipped_count -= 1
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,27 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-belt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
- - Kelly Redding
13
+ - Kelly D. Redding
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-06 00:00:00 -06:00
18
+ date: 2011-01-06 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: shoulda
22
+ name: bundler
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
25
40
  none: false
26
41
  requirements:
27
42
  - - ~>
@@ -32,11 +47,11 @@ dependencies:
32
47
  - 11
33
48
  version: "2.11"
34
49
  type: :runtime
35
- version_requirements: *id001
50
+ version_requirements: *id002
36
51
  - !ruby/object:Gem::Dependency
37
52
  name: leftright
38
53
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
40
55
  none: false
41
56
  requirements:
42
57
  - - ~>
@@ -48,11 +63,11 @@ dependencies:
48
63
  - 0
49
64
  version: 0.9.0
50
65
  type: :runtime
51
- version_requirements: *id002
66
+ version_requirements: *id003
52
67
  - !ruby/object:Gem::Dependency
53
68
  name: kelredd-useful
54
69
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
56
71
  none: false
57
72
  requirements:
58
73
  - - ~>
@@ -64,37 +79,51 @@ dependencies:
64
79
  - 0
65
80
  version: 0.4.0
66
81
  type: :runtime
67
- version_requirements: *id003
68
- description:
69
- email: kelly@kelredd.com
82
+ version_requirements: *id004
83
+ description: This is my Ruby testing "tool belt". It packages up the most common testing tools and paradigms I use. It is opinionated and custom to how I like to test.
84
+ email:
85
+ - kelly@kelredd.com
70
86
  executables: []
71
87
 
72
88
  extensions: []
73
89
 
74
- extra_rdoc_files:
75
- - README.rdoc
90
+ extra_rdoc_files: []
91
+
76
92
  files:
93
+ - .gitignore
94
+ - Gemfile
77
95
  - README.rdoc
78
96
  - Rakefile
97
+ - lib/test_belt.rb
79
98
  - lib/test_belt/helper.rb
80
99
  - lib/test_belt/rake_tasks.rb
100
+ - lib/test_belt/shoulda_macros.rb
81
101
  - lib/test_belt/shoulda_macros/classes.rb
82
102
  - lib/test_belt/shoulda_macros/context.rb
83
103
  - lib/test_belt/shoulda_macros/files.rb
84
- - lib/test_belt/shoulda_macros.rb
104
+ - lib/test_belt/test_unit.rb
85
105
  - lib/test_belt/test_unit/context.rb
86
106
  - lib/test_belt/test_unit/runner.rb
87
- - lib/test_belt/test_unit.rb
107
+ - lib/test_belt/test_unit/test_case.rb
88
108
  - lib/test_belt/version.rb
89
- - lib/test_belt.rb
109
+ - test-belt.gemspec
110
+ - test/env.rb
111
+ - test/fixtures/shoulda_macros/thing.rb
112
+ - test/helper.rb
113
+ - test/rake_tasks_test.rb
114
+ - test/shoulda_macros/classes_test.rb
115
+ - test/shoulda_macros/context_test.rb
116
+ - test/shoulda_macros/files_test.rb
117
+ - test/test_unit/context_test.rb
118
+ - test/test_unit/runner_test.rb
119
+ - test/test_unit/test_case_test.rb
90
120
  has_rdoc: true
91
121
  homepage: http://github.com/kelredd/test-belt
92
122
  licenses: []
93
123
 
94
124
  post_install_message:
95
- rdoc_options:
96
- - --main
97
- - README.rdoc
125
+ rdoc_options: []
126
+
98
127
  require_paths:
99
128
  - lib
100
129
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -122,5 +151,14 @@ rubygems_version: 1.3.7
122
151
  signing_key:
123
152
  specification_version: 3
124
153
  summary: A gem for using testing tools I like - my Ruby testing toolbelt.
125
- test_files: []
126
-
154
+ test_files:
155
+ - test/env.rb
156
+ - test/fixtures/shoulda_macros/thing.rb
157
+ - test/helper.rb
158
+ - test/rake_tasks_test.rb
159
+ - test/shoulda_macros/classes_test.rb
160
+ - test/shoulda_macros/context_test.rb
161
+ - test/shoulda_macros/files_test.rb
162
+ - test/test_unit/context_test.rb
163
+ - test/test_unit/runner_test.rb
164
+ - test/test_unit/test_case_test.rb