test-belt 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  /coverage/
4
4
  *.log
5
5
  .bundle
6
+ .rvmrc
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in i-env.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake', '~>0.9.2'
@@ -1,17 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-belt (1.1.2)
4
+ test-belt (2.0.0)
5
5
  leftright (~> 0.9.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  leftright (0.9.1)
11
+ rake (0.9.2)
11
12
 
12
13
  PLATFORMS
13
14
  ruby
14
15
 
15
16
  DEPENDENCIES
16
17
  bundler (~> 1.0)
18
+ rake (~> 0.9.2)
17
19
  test-belt!
@@ -22,16 +22,20 @@ 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', :require => 'test_belt'
25
+ gem 'test-belt'
26
26
 
27
27
  # other testing gem dependencies ...
28
28
  end
29
29
 
30
30
  == Test Helpers
31
- Requiring test belt loads in the testing libraries I like and use. In your test files or a common test helper file, require in test belt:
31
+ Requiring test belt loads in the testing libraries I like and use. First make sure all your tests are in a 'test' directory. Then in your test files require in test belt:
32
32
  require 'test_belt'
33
33
 
34
- This will give you the following tools. I use most of these helpers in testing this gem. To see examples of these in action, peruse this gem's test files (https://github.com/kelredd/test-belt/tree/master/test) and run the test suite with:
34
+ This does a few things for you:
35
+ * adds your 'lib' and 'test' dirs to the $LOAD_PATH
36
+ * requires in a 'test/helper' file if one exists
37
+
38
+ In addition, it gives you the following tools. I use most of these helpers in testing this gem. To see examples of these in action, peruse this gem's test files (https://github.com/kelredd/test-belt/tree/master/test) and run the test suite with:
35
39
  $ rake test
36
40
 
37
41
  === Test::Unit
@@ -83,7 +87,7 @@ To see what this gives you:
83
87
  $ rake -T
84
88
 
85
89
  === IRB with your environment loaded
86
- Many times in developing code, I need to quickly load up IRB with my environment. TestBelt will give you a rake task for doing that. Simply create an env.rb file that loads your environment in your test file directory (/test for example). See https://github.com/kelredd/test-belt/tree/master/test/env.rb and demo for this gem with:
90
+ Many times in developing code, I need to quickly load up IRB with my environment. TestBelt will give you a rake task for doing that. Simply create an irb.rb file in your test file directory and have it require 'test_belt'. See https://github.com/kelredd/test-belt/tree/master/test/irb.rb and demo for this gem with:
87
91
 
88
92
  $ rake irb
89
93
  > TestBelt
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
+ include Rake::DSL
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
- require 'lib/test_belt/rake_tasks'
6
+ require 'test_belt/rake_tasks'
5
7
  TestBelt::RakeTasks.for :test
6
8
 
7
9
  task :default => :build
@@ -0,0 +1,2 @@
1
+ # so you don't have to specify a :require opt in your Gemfile
2
+ require 'test_belt'
@@ -1,2 +1,4 @@
1
1
  module TestBelt; end
2
- require 'test_belt/helper'
2
+
3
+ require 'test_belt/setup'
4
+ TestBelt.setup(caller)
@@ -1,30 +1,2 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'leftright'
4
-
5
- require 'test_belt/utils'
6
- require 'test_belt/default_test'
7
- require 'test_belt/testcase'
8
- require 'test_belt/should'
9
- require 'test_belt/context'
10
- require 'test_belt/subject'
11
- require 'test_belt/skip'
12
- require 'test_belt/callbacks'
13
- require 'test_belt/matchers'
14
-
15
- module TestBelt
16
-
17
- def self.included(receiving_test_class)
18
- if receiving_test_class.ancestors.include?(::Test::Unit::TestCase)
19
- receiving_test_class.send(:include, DefaultTest)
20
- receiving_test_class.send(:include, TestCase)
21
- receiving_test_class.send(:extend, Should)
22
- receiving_test_class.send(:include, Context)
23
- receiving_test_class.send(:include, Subject)
24
- receiving_test_class.send(:include, Skip)
25
- receiving_test_class.send(:include, Callbacks)
26
- receiving_test_class.send(:include, Matchers)
27
- end
28
- end
29
-
30
- end
1
+ # for backwards compatibility
2
+ require 'test_belt/setup'
@@ -52,11 +52,11 @@ module TestBelt::RakeTasks
52
52
  end
53
53
 
54
54
  def irb_task(path)
55
- env_file = File.join(path, "env.rb")
56
- if File.exist?(env_file)
57
- desc "Open irb preloaded with #{env_file}"
55
+ irb_file = File.join(path, "irb.rb")
56
+ if File.exist?(irb_file)
57
+ desc "Open irb preloaded with #{irb_file}"
58
58
  task :irb do
59
- sh "irb -rubygems -r ./#{env_file}"
59
+ sh "irb -rubygems -r ./#{irb_file}"
60
60
  end
61
61
  end
62
62
  end
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'leftright'
4
+
5
+ require 'test_belt/utils'
6
+ require 'test_belt/default_test'
7
+ require 'test_belt/testcase'
8
+ require 'test_belt/should'
9
+ require 'test_belt/context'
10
+ require 'test_belt/subject'
11
+ require 'test_belt/skip'
12
+ require 'test_belt/callbacks'
13
+ require 'test_belt/matchers'
14
+
15
+ module TestBelt
16
+
17
+ def self.included(receiving_test_class)
18
+ if receiving_test_class.ancestors.include?(::Test::Unit::TestCase)
19
+ receiving_test_class.send(:include, DefaultTest)
20
+ receiving_test_class.send(:include, TestCase)
21
+ receiving_test_class.send(:extend, Should)
22
+ receiving_test_class.send(:include, Context)
23
+ receiving_test_class.send(:include, Subject)
24
+ receiving_test_class.send(:include, Skip)
25
+ receiving_test_class.send(:include, Callbacks)
26
+ receiving_test_class.send(:include, Matchers)
27
+ end
28
+ end
29
+
30
+
31
+ # assume the test dir path is ./test and the lib dir path ./test/../lib
32
+ TEST_DIR = "test"
33
+ LIB_DIR = "lib"
34
+ TEST_REGEX = /^#{TEST_DIR}$|^#{TEST_DIR}\/|\/#{TEST_DIR}\/|\/#{TEST_DIR}$/
35
+ TEST_HELPER_FILE = "helper"
36
+ class << self
37
+
38
+ # run some setup stuff based on the caller's info
39
+ def setup(caller_info)
40
+ if (crp = caller_root_path(caller_info))
41
+ add_caller_paths_to_load_path(crp)
42
+ require_caller_test_helper(crp)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ # add the caller's lib/test dirs to the load path
49
+ def add_caller_paths_to_load_path(root_path)
50
+ add_to_load_path(File.join(root_path, LIB_DIR))
51
+ add_to_load_path(File.join(root_path, TEST_DIR))
52
+ end
53
+
54
+ def add_to_load_path(dir)
55
+ $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
56
+ end
57
+
58
+ # require the caller's test/helper file if exists
59
+ def require_caller_test_helper(root_path)
60
+ if File.exists?(File.join(root_path, TEST_DIR, TEST_HELPER_FILE+'.rb')) &&
61
+ $LOAD_PATH.include?(File.join(root_path, TEST_DIR))
62
+ require TEST_HELPER_FILE
63
+ end
64
+ end
65
+
66
+ # this method inspects the caller info and finds the caller's root path
67
+ # this expects the caller's root path to be the parent dir of the first
68
+ # parent dir of caller named TEST_DIR
69
+ def caller_root_path(caller_info)
70
+ caller_dirname = File.expand_path(File.dirname(caller_info[0]))
71
+ if (test_dir_pos = caller_dirname.index(TEST_REGEX)) > 0
72
+ root_dir = caller_dirname[0..(test_dir_pos-1)]
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -1,3 +1,3 @@
1
1
  module TestBelt
2
- VERSION = "1.1.2"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- require "test/helper"
1
+ require "test_belt"
2
2
 
3
3
  module TestBelt
4
4
 
@@ -1 +1,2 @@
1
- require 'test/env'
1
+ # this file is automatically required in when you require 'test_belt'
2
+ # put test helpers here
@@ -1,4 +1,4 @@
1
- require "test/helper"
1
+ require "test_belt"
2
2
 
3
3
  module TestBelt
4
4
 
@@ -0,0 +1,8 @@
1
+ require 'test_belt'
2
+
3
+ # this file is required in when the 'irb' rake test is run
4
+ # b/c 'test_belt' is required above, lib and test dirs will
5
+ # be added to the LOAD_PATH and the test helper will be
6
+ # required in.
7
+
8
+ # put any IRB setup code here
@@ -1,5 +1,5 @@
1
- require "test/helper"
2
- require 'test/fixtures/thing'
1
+ require "test_belt"
2
+ require 'fixtures/thing'
3
3
 
4
4
  module TestBelt::Matchers
5
5
 
@@ -25,7 +25,7 @@ module TestBelt::Matchers
25
25
  should have_directory 'test'
26
26
  should have_directories './test/fixtures'
27
27
  should have_file 'test/fixtures/thing.rb'
28
- should have_files './test/env.rb', './test/helper.rb'
28
+ should have_files './test/irb.rb', './test/helper.rb'
29
29
  end
30
30
 
31
31
 
@@ -1,5 +1,5 @@
1
- require "test/helper"
2
- require 'lib/test_belt/rake_tasks'
1
+ require "test_belt"
2
+ require 'test_belt/rake_tasks'
3
3
 
4
4
  module TestBelt
5
5
  class RakeTasksTest < Test::Unit::TestCase
@@ -1,5 +1,5 @@
1
- require "test/helper"
2
- require 'test/fixtures/inherited_stuff'
1
+ require "test_belt"
2
+ require 'fixtures/inherited_stuff'
3
3
 
4
4
  module TestBelt::Utils
5
5
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-belt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
- - 1
8
- - 1
9
7
  - 2
10
- version: 1.1.2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly D. Redding
@@ -15,11 +15,9 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-05 00:00:00 Z
18
+ date: 2011-07-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: bundler
22
- prerelease: false
23
21
  requirement: &id001 !ruby/object:Gem::Requirement
24
22
  none: false
25
23
  requirements:
@@ -30,11 +28,11 @@ dependencies:
30
28
  - 1
31
29
  - 0
32
30
  version: "1.0"
33
- type: :development
34
31
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: leftright
37
32
  prerelease: false
33
+ name: bundler
34
+ type: :development
35
+ - !ruby/object:Gem::Dependency
38
36
  requirement: &id002 !ruby/object:Gem::Requirement
39
37
  none: false
40
38
  requirements:
@@ -46,8 +44,10 @@ dependencies:
46
44
  - 9
47
45
  - 0
48
46
  version: 0.9.0
49
- type: :runtime
50
47
  version_requirements: *id002
48
+ prerelease: false
49
+ name: leftright
50
+ type: :runtime
51
51
  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.
52
52
  email:
53
53
  - kelly@kelredd.com
@@ -63,6 +63,7 @@ files:
63
63
  - Gemfile.lock
64
64
  - README.rdoc
65
65
  - Rakefile
66
+ - lib/test-belt.rb
66
67
  - lib/test_belt.rb
67
68
  - lib/test_belt/callbacks.rb
68
69
  - lib/test_belt/callbacks/case.rb
@@ -80,6 +81,7 @@ files:
80
81
  - lib/test_belt/matchers/have_readers.rb
81
82
  - lib/test_belt/matchers/have_writers.rb
82
83
  - lib/test_belt/rake_tasks.rb
84
+ - lib/test_belt/setup.rb
83
85
  - lib/test_belt/should.rb
84
86
  - lib/test_belt/skip.rb
85
87
  - lib/test_belt/subject.rb
@@ -88,11 +90,11 @@ files:
88
90
  - lib/test_belt/version.rb
89
91
  - test-belt.gemspec
90
92
  - test/callbacks_test.rb
91
- - test/env.rb
92
93
  - test/fixtures/inherited_stuff.rb
93
94
  - test/fixtures/thing.rb
94
95
  - test/helper.rb
95
96
  - test/helpers_test.rb
97
+ - test/irb.rb
96
98
  - test/matchers_test.rb
97
99
  - test/rake_tasks_test.rb
98
100
  - test/utils_test.rb
@@ -131,11 +133,11 @@ specification_version: 3
131
133
  summary: A gem for using testing tools I like - my Ruby testing toolbelt.
132
134
  test_files:
133
135
  - test/callbacks_test.rb
134
- - test/env.rb
135
136
  - test/fixtures/inherited_stuff.rb
136
137
  - test/fixtures/thing.rb
137
138
  - test/helper.rb
138
139
  - test/helpers_test.rb
140
+ - test/irb.rb
139
141
  - test/matchers_test.rb
140
142
  - test/rake_tasks_test.rb
141
143
  - test/utils_test.rb
@@ -1,9 +0,0 @@
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'