duck_test 0.1.4

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 (45) hide show
  1. data/bin/ducktest +29 -0
  2. data/lib/duck_test/autoload_config.rb +103 -0
  3. data/lib/duck_test/base.rb +41 -0
  4. data/lib/duck_test/commands.rb +208 -0
  5. data/lib/duck_test/config.rb +675 -0
  6. data/lib/duck_test/config_helper.rb +99 -0
  7. data/lib/duck_test/console.rb +18 -0
  8. data/lib/duck_test/default_config.rb +48 -0
  9. data/lib/duck_test/frame_work/base.rb +587 -0
  10. data/lib/duck_test/frame_work/file_manager.rb +511 -0
  11. data/lib/duck_test/frame_work/filter_set.rb +233 -0
  12. data/lib/duck_test/frame_work/map.rb +331 -0
  13. data/lib/duck_test/frame_work/queue.rb +221 -0
  14. data/lib/duck_test/frame_work/queue_event.rb +29 -0
  15. data/lib/duck_test/frame_work/rspec/base.rb +17 -0
  16. data/lib/duck_test/frame_work/rspec/frame_work.rb +30 -0
  17. data/lib/duck_test/frame_work/test_unit/base.rb +14 -0
  18. data/lib/duck_test/frame_work/test_unit/frame_work.rb +33 -0
  19. data/lib/duck_test/frame_work/watch_config.rb +69 -0
  20. data/lib/duck_test/gem/helper.rb +107 -0
  21. data/lib/duck_test/logger.rb +127 -0
  22. data/lib/duck_test/option_parser.rb +30 -0
  23. data/lib/duck_test/platforms/base.rb +18 -0
  24. data/lib/duck_test/platforms/dependencies.rb +18 -0
  25. data/lib/duck_test/platforms/generic/base.rb +15 -0
  26. data/lib/duck_test/platforms/generic/listener.rb +104 -0
  27. data/lib/duck_test/platforms/linux/base.rb +15 -0
  28. data/lib/duck_test/platforms/linux/listener.rb +76 -0
  29. data/lib/duck_test/platforms/listener.rb +303 -0
  30. data/lib/duck_test/platforms/mac/base.rb +15 -0
  31. data/lib/duck_test/platforms/mac/listener.rb +79 -0
  32. data/lib/duck_test/platforms/mac/listener.rb.orig +147 -0
  33. data/lib/duck_test/platforms/os_helper.rb +102 -0
  34. data/lib/duck_test/platforms/watch_event.rb +47 -0
  35. data/lib/duck_test/platforms/windows/base.rb +15 -0
  36. data/lib/duck_test/platforms/windows/listener.rb +123 -0
  37. data/lib/duck_test/railtie.rb +29 -0
  38. data/lib/duck_test/usage.rb +34 -0
  39. data/lib/duck_test/usage.yml +112 -0
  40. data/lib/duck_test/version.rb +3 -0
  41. data/lib/duck_test.rb +6 -0
  42. data/lib/notes.txt +215 -0
  43. data/lib/tasks/duck_tests.rake +35 -0
  44. data/lib/tasks/gem_tasks.rake +18 -0
  45. metadata +92 -0
data/bin/ducktest ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'rubygems'
4
+
5
+ version = ">= 0"
6
+
7
+ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
8
+ version = $1
9
+ ARGV.shift
10
+ end
11
+
12
+ # get a list of all arguments passed on the CLI that DO NOT begin with a hyphen
13
+ values = ARGV.find_all {|item| !item.match(/^-/)}
14
+
15
+ # remove any arguments that DO NOT exist in the args array
16
+ args = %w(c development production test)
17
+ values.delete_if {|arg| args.include?(arg)}
18
+
19
+ # the remaining arguments should be arguments that are NOT SUPPORTED via the console, however,
20
+ # are useful for ducktest. Save them for later use.
21
+ if ENV["DUCK_TEST"].nil? || ENV["DUCK_TEST"].empty?
22
+ ENV["DUCK_TEST"] = values.first
23
+ end
24
+
25
+ # now, remove them from the CLI args so the console doesn't puke...
26
+ ARGV.delete_if {|arg| values.include?(arg)}
27
+
28
+ gem 'rails', version
29
+ load Gem.bin_path('rails', 'rails', version)
@@ -0,0 +1,103 @@
1
+ module DuckTest
2
+
3
+ ##################################################################################
4
+ # Helper methods for configuring autoload paths during startup. One of the requirements essential to running tests in the console
5
+ # is making all of the module and class files visible to the console environment. Typically, this is accomplished via config/application.rb
6
+ # by adding to the autoload_paths like the following:
7
+ #
8
+ # config.autoload_paths += %W(#{Rails.root}/test)
9
+ #
10
+ # During startup DuckTest will attempt to take this step for you prior to configuration using a before_configuration block inside
11
+ # the Railtie class for the gem. You can guide this behavior in a couple of ways using a config file in two locations.
12
+ #
13
+ # - In the home directory of your file system: ~/.ducktestrc
14
+ # - In the root directory of your Rails application: Rails.root/.ducktest
15
+ #
16
+ # Notice the slight difference in the file names. One with rc and one without. The default configuration is to load each directory for
17
+ # each supported testing framework if the directory exists. Currently, testunit and rspec are the two testing frameworks.
18
+ # The startup process goes something like this:
19
+ #
20
+ # 1. load configuration settings from disk
21
+ # 2. determine the current Rails environment: test, development, production.
22
+ # 3. loop thru each directory from the config. if the directory is configured to be added to the autoload_path and
23
+ # the directory actually exists, then, it is added, otherwise, it is ignored.
24
+ #
25
+ # The following is a sample config file.
26
+ # ---
27
+ # test: # represents the Rails environment
28
+ # test: true # represents an app directory directly off of the app root
29
+ # spec: true
30
+ #
31
+ # development:
32
+ # test: true
33
+ # spec: false
34
+ #
35
+ # The default configuration is to add test and spec directories to the autoload_path. You can easily prevent any of them by setting
36
+ # the boolean value to false. You can add additional directories by adding the directory name and true.
37
+ #
38
+ # Load order:
39
+ # The default config for test and development is to add the test and spec directories if they exist. The config file ~/.ducktestrc
40
+ # in the home directory is loaded and merged with the default config and will override it's values. Next, the config file .ducktest in the app
41
+ # directory is loaded and merged with the default config and will override it's values. So, the rule is simple.
42
+ # - home directory overrides default
43
+ # - app directory overrides both
44
+ class AutoloadConfig
45
+ include LoggerHelper
46
+
47
+ attr_accessor :paths
48
+
49
+ ##################################################################################
50
+ # Do I really have to say it?
51
+ def initialize
52
+ super
53
+ self.paths = []
54
+ self.load_config
55
+ end
56
+
57
+ ##################################################################################
58
+ # Loads config settings for autoload paths
59
+ def load_config
60
+ config = {test: {test: true, spec: true}, development: {test: false, spec: false}}
61
+
62
+ if File.exists?("~/.ducktestrc")
63
+ config = merge(config, YAML.load_file("~/.ducktestrc"))
64
+ end
65
+
66
+ if File.exists?("#{Rails.root}/.ducktest")
67
+ config = merge(config, YAML.load_file("#{Rails.root}/.ducktest"))
68
+ end
69
+
70
+ config.each do |item|
71
+ if Rails.env.eql?(item.first.to_s)
72
+ item.last.each do |path|
73
+ if path.last
74
+ file_spec = "#{Rails.root}/#{path.first}"
75
+ if File.exist?(file_spec)
76
+ self.paths.push(file_spec)
77
+ ducklog.system "Adding path to autoload_paths: #{file_spec}"
78
+ end
79
+ end
80
+ end
81
+ break
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ ##################################################################################
88
+ # Loads config settings for autoload paths
89
+ def merge(config, buffer)
90
+ buffer = buffer.symbolize_keys
91
+ config.each do |item|
92
+ if item.last.kind_of?(Hash)
93
+ if buffer[item.first]
94
+ item.last.merge!(buffer[item.first].symbolize_keys)
95
+ end
96
+ end
97
+ end
98
+ return config
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,41 @@
1
+ # DuckTest Base module
2
+ require "duck_test/version"
3
+
4
+ module DuckTest
5
+
6
+ autoload :AutoloadConfig, 'duck_test/autoload_config'
7
+ autoload :Config, 'duck_test/config'
8
+ autoload :ConfigHelper, 'duck_test/config_helper'
9
+ autoload :Console, 'duck_test/console'
10
+ autoload :Commands, 'duck_test/commands'
11
+ autoload :DefaultConfig, 'duck_test/default_config'
12
+ autoload :FrameWork, 'duck_test/frame_work/base'
13
+ autoload :Logger, 'duck_test/logger'
14
+ autoload :LoggerHelper, 'duck_test/logger'
15
+ autoload :Platforms, 'duck_test/platforms/base'
16
+ autoload :Usage, 'duck_test/usage'
17
+ autoload :VersionHelper, 'duck_test/version'
18
+
19
+ ##################################################################################
20
+ # Executes a configuration block to define watch lists, etc.
21
+ #
22
+ # DuckTest.config do
23
+ #
24
+ # runnable "**/*"
25
+ #
26
+ # end
27
+ #
28
+ # @return [DuckTest::Config] Returns DuckTest::Config instance if a block is passed.
29
+ def self.config(&block)
30
+ config = nil
31
+
32
+ if block_given?
33
+ config = DuckTest::Config.new
34
+ config.instance_exec(&block)
35
+ config.class.block_run = true
36
+ end
37
+
38
+ return config
39
+ end
40
+
41
+ end
@@ -0,0 +1,208 @@
1
+ module DuckTest
2
+
3
+ # Console commands
4
+ class Commands
5
+
6
+ include LoggerHelper
7
+ include Usage
8
+
9
+ ##################################################################################
10
+ def initialize
11
+ super
12
+ end
13
+
14
+ ##################################################################################
15
+ # Displays standard usage details
16
+ def to_s
17
+ usage(:usage, true)
18
+ return nil
19
+ end
20
+
21
+ ##################################################################################
22
+ # See {Logger.log_level}
23
+ # @return [String] The output message
24
+ def ar(value = nil)
25
+ if value.blank?
26
+ usage(:ar, true)
27
+ msg = "Current log level: #{Logger.to_severity(ActiveRecord::Base.logger.level)}"
28
+ else
29
+ # converts from a symbol to a number
30
+ ActiveRecord::Base.logger.level = Logger.to_severity(value)
31
+ msg = "Log level set to: #{value}"
32
+ end
33
+ return msg
34
+ end
35
+
36
+ ##################################################################################
37
+ # Toggles autorun on/off.
38
+ # @return [String] The output message
39
+ def autorun
40
+ return DuckTest::Config.framework.toggle_autorun
41
+ end
42
+
43
+ ##################################################################################
44
+ # Lists all of the files that have been blacklisted.
45
+ # @return [String] The output message
46
+ def blacklist
47
+ list = []
48
+ DuckTest::Config.framework.black_list.each {|item| list.push(item.first)}
49
+ list.sort.each {|item| ducklog.console item}
50
+ return ""
51
+ end
52
+
53
+ ##################################################################################
54
+ # Lists all of the non-runnable and runnable files that have been loaded into memory during the current session.
55
+ # @return [String] The output message
56
+ def history
57
+ framework = DuckTest::Config.framework
58
+
59
+ ducklog.console "================================="
60
+
61
+ if framework.non_loadable_history.length > 0 || framework.non_runnable_history.length > 0 || framework.runnable_history.length > 0
62
+
63
+ ducklog.console "\r\n Non-loadable file(s)" if framework.non_loadable_history.length > 0
64
+
65
+ framework.non_loadable_history.each do |file_spec|
66
+ ducklog.console " #{file_spec.gsub("#{framework.root}#{File::SEPARATOR}", "")}"
67
+ end
68
+
69
+ ducklog.console "\r\n Non-runnable file(s)" if framework.non_runnable_history.length > 0
70
+
71
+ framework.non_runnable_history.each do |file_spec|
72
+ ducklog.console " #{file_spec.gsub("#{framework.root}#{File::SEPARATOR}", "")}"
73
+ end
74
+
75
+ ducklog.console "\r\n Runnable file(s)" if framework.runnable_history.length > 0
76
+
77
+ framework.runnable_history.each do |file_spec|
78
+ ducklog.console " #{file_spec.gsub("#{framework.root}#{File::SEPARATOR}", "")}"
79
+ end
80
+
81
+ else
82
+ ducklog.console " Zero files have been changed and run"
83
+ end
84
+
85
+ return ""
86
+ end
87
+
88
+ ##################################################################################
89
+ # Displays information about the current loaded testing framework.
90
+ # @return [String] The output message
91
+ def info
92
+ puts DuckTest::Config.framework.info
93
+ return ""
94
+ end
95
+
96
+ ##################################################################################
97
+ # See {FrameWork::Queue#latency}
98
+ # @return [String] The output message
99
+ def latency(value = nil)
100
+ unless usage(:latency, value.blank?)
101
+ DuckTest::Config.framework.set_latency(value.to_f)
102
+ msg = "Queue latency set to: #{value}"
103
+ end
104
+ return msg
105
+ end
106
+
107
+ ##################################################################################
108
+ # See {Platforms::Listener#speed}
109
+ # @return [String] The output message
110
+ def listen_speed(value = nil)
111
+ msg = nil
112
+ unless usage(:listen_speed, value.blank?)
113
+ DuckTest::Config.framework.set_listener_speed(value.to_f)
114
+ msg = "Listener speed set to: #{value}"
115
+ end
116
+ return msg
117
+ end
118
+
119
+ ##################################################################################
120
+ # See {Logger.log_level}
121
+ # @return [String] The output message
122
+ def ll(value = nil)
123
+ if value.blank?
124
+ usage(:ll, true)
125
+ msg = "Current log level: #{Logger.to_severity(Logger.log_level)}"
126
+ else
127
+ Logger.log_level = value
128
+ msg = "Log level set to: #{value}"
129
+ end
130
+ return msg
131
+ end
132
+
133
+ ##################################################################################
134
+ # Lists mappings of non-runnable to runnable files.
135
+ # @return [String] The output message
136
+ def maps
137
+ framework = DuckTest::Config.framework
138
+
139
+ framework.watch_configs.each do |watch_config|
140
+ ducklog.console "================================="
141
+ ducklog.console " pattern: #{watch_config.pattern}"
142
+ ducklog.console " runnrable?: #{watch_config.runnable?}"
143
+ ducklog.console " maps?: #{watch_config.maps.length > 0 ? true : false}"
144
+ ducklog.console ""
145
+
146
+ if watch_config.maps.length > 0
147
+ framework.white_list.each do |file_object|
148
+ if file_object.last[:watch_config].eql?(watch_config)
149
+ unless file_object.last[:is_dir]
150
+ runnable_files = framework.find_runnable_files(file_object.first, file_object.last[:watch_config])
151
+ if runnable_files.length > 0
152
+ ducklog.console " #{file_object.first.gsub("#{framework.root}#{File::SEPARATOR}", "")}"
153
+ runnable_files.each do |file_spec|
154
+ ducklog.console " executes ==> #{file_spec.gsub("#{framework.root}#{File::SEPARATOR}", "")}"
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ end
163
+
164
+ return ""
165
+ end
166
+
167
+ ##################################################################################
168
+ # Runs all tests that have been automagically loaded via the queue as a result of a file change or
169
+ # loaded manually with the load command.
170
+ # @return [String] The output message
171
+ def run(value=nil)
172
+ unless usage(:run, value.kind_of?(Symbol) && value.eql?(:help))
173
+ return DuckTest::Config.framework.run_manually(value)
174
+ end
175
+ end
176
+
177
+ ##################################################################################
178
+ # Loads all runnable test files from disk and executes the run_tests method.
179
+ # @return [String] The output message
180
+ def runall
181
+ return DuckTest::Config.framework.run_all
182
+ end
183
+
184
+ ##################################################################################
185
+ # See {FrameWork::Queue#speed}
186
+ # @return [String] The output message
187
+ def speed(value = nil)
188
+ msg = nil
189
+ unless usage(:speed, value.blank?)
190
+ DuckTest::Config.framework.set_queue_speed(value.to_f)
191
+ msg = "Queue speed set to: #{value}"
192
+ end
193
+ return msg
194
+ end
195
+
196
+ ##################################################################################
197
+ # Lists all of the files that have been whitelisted.
198
+ # @return [String] The output message
199
+ def whitelist
200
+ list = []
201
+ DuckTest::Config.framework.white_list.each {|item| list.push(item.first)}
202
+ list.sort.each {|item| ducklog.console item}
203
+ return ""
204
+ end
205
+
206
+ end
207
+ end
208
+