assert 1.1.0 → 2.0.0.rc.1

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.
Files changed (49) hide show
  1. data/.assert.rb +3 -0
  2. data/README.md +182 -108
  3. data/Rakefile +0 -3
  4. data/bin/assert +1 -1
  5. data/lib/assert.rb +75 -4
  6. data/lib/assert/assert_runner.rb +76 -0
  7. data/lib/assert/cli.rb +25 -46
  8. data/lib/assert/context.rb +3 -3
  9. data/lib/assert/result.rb +65 -55
  10. data/lib/assert/runner.rb +19 -38
  11. data/lib/assert/suite.rb +0 -7
  12. data/lib/assert/test.rb +4 -16
  13. data/lib/assert/version.rb +1 -1
  14. data/lib/assert/view.rb +23 -0
  15. data/lib/assert/view/base.rb +10 -19
  16. data/lib/assert/view/default_view.rb +16 -11
  17. data/lib/assert/view/helpers/ansi_styles.rb +1 -1
  18. data/lib/assert/view/helpers/common.rb +37 -16
  19. data/test/assert_test.rb +29 -14
  20. data/test/context/class_methods_test.rb +2 -2
  21. data/test/context_test.rb +28 -50
  22. data/test/helper.rb +4 -2
  23. data/test/runner_test.rb +5 -4
  24. data/test/suite_test.rb +1 -1
  25. data/test/test_test.rb +8 -15
  26. data/test/view/base_tests.rb +20 -37
  27. metadata +17 -39
  28. data/lib/assert/autorun.rb +0 -37
  29. data/lib/assert/options.rb +0 -43
  30. data/lib/assert/rake_tasks.rb +0 -75
  31. data/lib/assert/rake_tasks/irb.rb +0 -33
  32. data/lib/assert/rake_tasks/scope.rb +0 -100
  33. data/lib/assert/rake_tasks/test_task.rb +0 -66
  34. data/lib/assert/result_set.rb +0 -17
  35. data/lib/assert/setup.rb +0 -3
  36. data/lib/assert/setup/all.rb +0 -5
  37. data/lib/assert/setup/helpers.rb +0 -72
  38. data/lib/assert/setup/options.rb +0 -6
  39. data/lib/assert/setup/runner.rb +0 -13
  40. data/lib/assert/setup/suite.rb +0 -13
  41. data/lib/assert/setup/view.rb +0 -39
  42. data/lib/assert/view/helpers/capture_output.rb +0 -23
  43. data/test/default_view_test.rb +0 -16
  44. data/test/irb.rb +0 -5
  45. data/test/options_test.rb +0 -40
  46. data/test/rake_tasks/irb_test.rb +0 -45
  47. data/test/rake_tasks/scope_test.rb +0 -63
  48. data/test/rake_tasks/test_task_test.rb +0 -80
  49. data/test/result_set_test.rb +0 -72
@@ -1,100 +0,0 @@
1
- require 'rake/tasklib'
2
- require 'assert/rake_tasks/test_task'
3
-
4
- module Assert::RakeTasks
5
- class Scope
6
-
7
- def self.test_file_suffixes
8
- ['_test.rb', '_tests.rb']
9
- end
10
-
11
- attr_reader :path, :nested_files, :path_file_list, :test_tasks, :scopes
12
-
13
- def initialize(path)
14
- @path = path
15
-
16
- @nested_files = get_nested_files
17
- @path_file_list = build_path_file_list
18
- @test_tasks = build_test_tasks
19
- @scopes = build_scopes
20
- end
21
-
22
- def namespace
23
- File.basename(@path).to_sym
24
- end
25
-
26
- # return a test task covering the scopes nested files plus path file
27
- # but only if there are nested files
28
- def to_test_task
29
- if !self.nested_files.empty?
30
- TestTask.new(@path) do |tt|
31
- tt.files = self.path_file_list + self.nested_files
32
- end
33
- end
34
- end
35
-
36
- protected
37
-
38
- # nested test files under the path
39
-
40
- def get_nested_files
41
- self.class.test_file_suffixes.map do |suffix|
42
- Rake::FileList["#{@path}/**/*#{suffix}"]
43
- end.flatten
44
- end
45
-
46
- # a list with the path test file "#{path}_test.rb" (if it exists)
47
-
48
- def build_path_file_list
49
- self.class.test_file_suffixes.map do |suffix|
50
- path_file_name = "#{@path}#{suffix}"
51
- File.exists?(path_file_name) ? Rake::FileList[path_file_name] : []
52
- end.flatten
53
- end
54
-
55
- # a collection of test tasks for every standalone child test file
56
-
57
- def build_test_tasks
58
- self.class.test_file_suffixes.map do |suffix|
59
- # get immediate child test files
60
- Dir.glob("#{@path}/*#{suffix}").collect do |f|
61
- # get just the path name for each file
62
- File.join(File.dirname(f), File.basename(f, suffix))
63
- end
64
- end.flatten.reject do |p|
65
- # reject any that have deeply nested test files
66
- self.class.test_file_suffixes.inject(false) do |result, suffix|
67
- result || !Dir.glob("#{p}/**/*#{suffix}").empty?
68
- end
69
- end.collect do |p|
70
- # build a test task for the standalone test file of the path
71
- TestTask.new(p) do |tt|
72
- tt.files = self.class.test_file_suffixes.map do |suffix|
73
- (File.exists?("#{p}#{suffix}") ? Rake::FileList["#{p}#{suffix}"] : [])
74
- end.flatten
75
- end
76
- end
77
- end
78
-
79
- # a collection of scopes for every child test dir or test dir/file combo
80
-
81
- def build_scopes
82
- self.class.test_file_suffixes.map do |suffix|
83
- # get immediate child paths
84
- Dir.glob("#{@path}/*").collect do |p|
85
- # get just the path name for each dir/file and uniq it
86
- File.join(File.dirname(p), File.basename(p, suffix))
87
- end
88
- end.flatten.uniq.select do |p|
89
- # select any that have deeply nested test files
90
- self.class.test_file_suffixes.inject(false) do |result, suffix|
91
- result || !Dir.glob("#{p}/**/*#{suffix}").empty?
92
- end
93
- end.collect do |p|
94
- # build a scope for each path
95
- self.class.new(p)
96
- end
97
- end
98
-
99
- end
100
- end
@@ -1,66 +0,0 @@
1
- require 'assert/rake_tasks/scope'
2
-
3
- module Assert::RakeTasks
4
-
5
- class TestTask
6
-
7
- attr_accessor :name, :path, :files
8
-
9
- # Create a testing task
10
- def initialize(path)
11
- @path = path
12
- @files = []
13
- yield self if block_given?
14
- end
15
-
16
- def relative_path
17
- File.join(@path.to_s.split(File::SEPARATOR)[1..-1])
18
- end
19
-
20
- def scope_description
21
- relative_path.empty? ? "" : " for #{relative_path}"
22
- end
23
-
24
- def description
25
- "Run all tests#{scope_description}"
26
- end
27
-
28
- def name
29
- # File.basename(@path, Scope.test_file_suffix).to_sym
30
- @name ||= File.basename(@path).tap do |bname|
31
- Scope.test_file_suffixes.each { |suffix| bname.gsub(suffix, '') }
32
- end.to_sym
33
- end
34
-
35
- def file_list # :nodoc:
36
- self.files.collect{|f| "\"#{f}\""}.join(' ')
37
- end
38
-
39
- def ruby_args
40
- [ "-rrubygems",
41
- "\"#{self.rake_loader}\"",
42
- self.file_list
43
- ].compact.join(" ")
44
- end
45
-
46
- def show_loaded_files?
47
- ENV["show_loaded_files"] == 'true'
48
- end
49
-
50
- protected
51
-
52
- def rake_loader
53
- find_file('rake/rake_test_loader')
54
- end
55
-
56
- def find_file(fn) # :nodoc:
57
- $LOAD_PATH.each do |path|
58
- file_path = File.join(path, "#{fn}.rb")
59
- return file_path if File.exist? file_path
60
- end
61
- nil
62
- end
63
-
64
- end
65
-
66
- end
@@ -1,17 +0,0 @@
1
- module Assert
2
- class ResultSet < ::Array
3
-
4
- attr_accessor :callback
5
-
6
- def initialize(callback=nil)
7
- @callback = callback
8
- super()
9
- end
10
-
11
- def <<(result)
12
- super
13
- @callback.call(result) if @callback
14
- end
15
-
16
- end
17
- end
@@ -1,3 +0,0 @@
1
- require 'assert/setup/all'
2
-
3
- Assert::Helpers.load(caller)
@@ -1,5 +0,0 @@
1
- require 'assert/setup/options'
2
- require 'assert/setup/suite'
3
- require 'assert/setup/view'
4
- require 'assert/setup/runner'
5
- require 'assert/setup/helpers'
@@ -1,72 +0,0 @@
1
- module Assert
2
- module Helpers
3
-
4
- # when Assert is required it will automatically require in two helper files
5
- # if they exist:
6
- # * "./test/helper.rb - package-specific helpers
7
- # * ~/.assert.rb - user-specific helpers (options, view, etc...)
8
- # the user-specific helper file will always be required in after the
9
- # package-specific one
10
-
11
- USER_TEST_DIR = './.assert'
12
- USER_TEST_HELPER = 'options'
13
-
14
- class << self
15
-
16
- # assume the test dir path is ./test and look for helpers in ./test/helper.rb
17
- def package_test_dir
18
- "test"
19
- end
20
- def package_helper_name
21
- "helper"
22
- end
23
- def package_test_helper_regex
24
- /^#{package_test_dir}$|^#{package_test_dir}\/|\/#{package_test_dir}\/|\/#{package_test_dir}$/
25
- end
26
-
27
- def load(caller_info)
28
- if (crp = caller_root_path(caller_info))
29
- require_package_test_helper(crp)
30
- end
31
- require_user_test_helper
32
- end
33
-
34
- private
35
-
36
- def require_user_test_helper
37
- if ENV['HOME']
38
- helper_path = File.join(USER_TEST_DIR, USER_TEST_HELPER)
39
- safe_require File.expand_path(helper_path, ENV['HOME'])
40
- end
41
- end
42
-
43
- # require the package's test/helper file if it exists
44
- def require_package_test_helper(root_path)
45
- safe_require package_helper_file(root_path)
46
- end
47
-
48
- def package_helper_file(root_path)
49
- File.join(root_path, package_test_dir, package_helper_name)
50
- end
51
-
52
- def safe_require(helper_file)
53
- if File.exists?(helper_file+".rb")
54
- require helper_file
55
- end
56
- end
57
-
58
- # this method inspects the caller info and finds the caller's root path
59
- # this expects the caller's root path to be the parent dir of the first
60
- # parent dir of caller named TEST_DIR
61
- def caller_root_path(caller_info)
62
- non_custom_require_caller_info = caller_info.reject{|i| i =~ /rubygems\/custom_require.rb/}
63
- caller_dirname = File.expand_path(File.dirname(non_custom_require_caller_info[0]))
64
- test_dir_pos = caller_dirname.index(package_test_helper_regex)
65
- if test_dir_pos && (test_dir_pos > 0)
66
- caller_dirname[0..(test_dir_pos-1)]
67
- end
68
- end
69
- end
70
-
71
- end
72
- end
@@ -1,6 +0,0 @@
1
- require 'assert/options'
2
-
3
- module Assert
4
- include Assert::Options
5
- options {}
6
- end
@@ -1,13 +0,0 @@
1
- require 'assert/options'
2
- require 'assert/runner'
3
-
4
- module Assert
5
-
6
- # Setup the default global runner for running tests
7
- options do
8
- default_runner Runner
9
- end
10
-
11
- def self.runner; self.options.runner; end
12
-
13
- end
@@ -1,13 +0,0 @@
1
- require 'assert/context'
2
- require 'assert/suite'
3
-
4
- module Assert
5
-
6
- # Setup the default global suite for collecting tests as contexts are defined
7
- options do
8
- default_suite Suite.new
9
- end
10
-
11
- def self.suite; self.options.suite; end
12
-
13
- end
@@ -1,39 +0,0 @@
1
- require 'assert/setup/helpers'
2
- require 'assert/view/default_view'
3
-
4
- module Assert
5
-
6
- # Setup the default view, rendering on $stdout
7
- # (override in user or package helpers)
8
- options do
9
- default_view View::DefaultView.new($stdout)
10
- end
11
-
12
- def self.view; self.options.view; end
13
-
14
- module View
15
-
16
- # this method is used to bring in custom user-specific views
17
- # require views by passing either a full path to the view ruby file
18
- # or passing the name of a view installed in ~/.assert/views
19
-
20
- def self.require_user_view(view)
21
- user_test_root = File.expand_path(Assert::Helpers::USER_TEST_DIR, ENV['HOME'])
22
- views_file = File.join(user_test_root, 'views', view, 'lib', view)
23
-
24
- if File.exists?(view) || File.exists?(view+'.rb')
25
- require view
26
- elsif ENV['HOME'] && File.exists?(views_file+'.rb')
27
- require views_file
28
- else
29
- msg = "[WARN] Can't find or require #{view.inspect} view."
30
- if !view.match(/\A\//)
31
- msg << " Did you install it in `~/.assert/views`?"
32
- end
33
- warn msg
34
- end
35
- end
36
-
37
- end
38
-
39
- end
@@ -1,23 +0,0 @@
1
- module Assert::View::Helpers
2
-
3
- module CaptureOutput
4
-
5
- def captured_output(output)
6
- if !output.empty?
7
- # TODO: move to the base view
8
- [ captured_output_start_msg,
9
- output + captured_output_end_msg
10
- ].join("\n")
11
- end
12
- end
13
-
14
- def captured_output_start_msg
15
- "--- stdout ---"
16
- end
17
- def captured_output_end_msg
18
- "--------------"
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,16 +0,0 @@
1
- require 'assert'
2
- require 'assert/setup/view'
3
-
4
- module Assert
5
-
6
- class DefaultViewTests < Assert::Context
7
- desc "assert's default view"
8
- subject { Assert.options.default_view }
9
-
10
- should "be the DefaultView" do
11
- assert_kind_of View::DefaultView, subject
12
- end
13
-
14
- end
15
-
16
- end
@@ -1,5 +0,0 @@
1
- # require in any test helper and load user settings
2
- require 'assert/setup'
3
-
4
- # this file is required in when the 'irb' rake test is run.
5
- # put any IRB setup code here
@@ -1,40 +0,0 @@
1
- require 'assert'
2
- require 'assert/options'
3
-
4
- module Assert::Options
5
-
6
- class BaseTest < Assert::Context
7
- desc "user options class"
8
- setup { @base = Assert::Options::Base.new }
9
- subject { @base }
10
-
11
- should "write single values by making a method call w/ a single arg" do
12
- subject.a_value 1
13
- assert_equal 1, subject.a_value
14
- end
15
-
16
- should "read values by making a method call w/ no args" do
17
- assert_equal nil, subject.a_value
18
- subject.a_value "blah"
19
- assert_equal "blah", subject.a_value
20
- end
21
-
22
- should "write an array of values by making a method call w/ multiple args" do
23
- subject.a_value [1,2,3]
24
- subject.values 1,2,3
25
- assert_equal subject.a_value, subject.values
26
- end
27
-
28
- should "write default values using the 'default_' prefix" do
29
- assert_equal nil, subject.a_value
30
- subject.default_a_value "def"
31
- assert_equal "def", subject.default_a_value
32
- assert_equal "def", subject.a_value
33
- subject.a_value "changed"
34
- assert_equal "def", subject.default_a_value
35
- assert_equal "changed", subject.a_value
36
- end
37
-
38
- end
39
-
40
- end
@@ -1,45 +0,0 @@
1
- require 'assert'
2
-
3
- require 'assert/rake_tasks/irb'
4
-
5
- module Assert::RakeTasks
6
-
7
- class IrbTests < Assert::Context
8
- desc "the irb task handler"
9
- setup do
10
- @root_path = File.expand_path('../../../test', __FILE__)
11
- @handler = Assert::RakeTasks::Irb.new(@root_path)
12
- end
13
- subject { @handler }
14
-
15
- should have_class_method :task_name, :file_name
16
- should have_instance_methods :file_path, :helper_exists?, :description, :cmd
17
-
18
- should "know its rake task name" do
19
- assert_equal :irb, subject.class.task_name
20
- end
21
-
22
- should "know the irb helper file name" do
23
- assert_equal "irb.rb", subject.class.file_name
24
- end
25
-
26
- should "know the irb helper file path" do
27
- assert_equal File.join(@root_path.to_s, subject.class.file_name), subject.file_path
28
- end
29
-
30
- should "know if the irb helper exists" do
31
- # this is true b/c assert has a test/helper.rb file defined
32
- assert_equal true, subject.helper_exists?
33
- end
34
-
35
- should "know the description of the irb task" do
36
- assert_equal "Open irb preloaded with #{subject.file_path}", subject.description
37
- end
38
-
39
- should "know the shell command to run the irb task" do
40
- assert_equal "irb -rubygems -r #{subject.file_path}", subject.cmd
41
- end
42
-
43
- end
44
-
45
- end