marcinbunsch-bolt 0.2.6 → 0.2.7

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.
data/lib/bolt.rb CHANGED
@@ -23,19 +23,25 @@ module Bolt
23
23
  # read the .bolt file for configuration
24
24
  def self.read_dotfile
25
25
  if File.exists?('.bolt')
26
- $stdout.puts "** Found .bolt file" if Bolt['verbose']
27
- read = YAML.load_file('.bolt')
28
- @@config.merge!(read) if read
26
+ parsed_dotfile = YAML.load_file('.bolt')
27
+ @@config.merge!(parsed_dotfile) if parsed_dotfile
28
+ $stdout.puts "** Found .bolt file" if Bolt.verbose?
29
29
  end
30
30
  end
31
31
 
32
32
  # read the arguments passed in cli
33
33
  def self.read_argv
34
34
  ARGV.each do |arg|
35
- self['verbose'] = true if arg == '-v'
35
+ @@config['verbose'] = true if arg == '-v'
36
36
  end
37
37
  end
38
38
 
39
+ # check for verbose execution
40
+ def self.verbose?
41
+ @@config['verbose'] || false
42
+ end
43
+
44
+ # start bolt
39
45
  def self.start
40
46
  $stdout.puts "** Starting Bolt..."
41
47
 
@@ -1,6 +1,6 @@
1
- module Bolt
2
- module Adapters
3
- module Rails
1
+ module Bolt #:nodoc:
2
+ module Adapters #:nodoc:
3
+ module Rails #:nodoc:
4
4
  end
5
5
  end
6
6
  end
@@ -10,9 +10,9 @@ ENV['RAILS_ENV'] = 'test'
10
10
  require 'config/environment.rb'
11
11
 
12
12
  # This is a hack for Rails Test::Unit to prevent raising errors when a test file is loaded again
13
- module ActiveSupport
14
- module Testing
15
- module Declarative
13
+ module ActiveSupport #:nodoc:
14
+ module Testing #:nodoc:
15
+ module Declarative #:nodoc:
16
16
  # test "verify something" do
17
17
  # ...
18
18
  # end
@@ -35,7 +35,7 @@ end
35
35
  # These hacks disable caching in views
36
36
  module ActionView #:nodoc:
37
37
  class PathSet #:nodoc:
38
- class Path
38
+ class Path #:nodoc:
39
39
  def eager_load_templates?
40
40
  false
41
41
  end
@@ -45,8 +45,8 @@ end
45
45
 
46
46
  # disable the class check in initialize for path
47
47
  module ActionView #:nodoc:
48
- class Template
49
- class Path
48
+ class Template #:nodoc:
49
+ class Path #:nodoc:
50
50
  def initialize(path)
51
51
  # raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
52
52
  @path = path.freeze
@@ -70,10 +70,10 @@ end
70
70
 
71
71
  # Rails < 2.3.0
72
72
  if Rails::VERSION::STRING =~ /^2\.3\.0/ || Rails::VERSION::STRING =~ /^2\.[0-2]\.[0-9]/
73
- module ActionView
73
+ module ActionView #:nodoc:
74
74
  # NOTE: The template that this mixin is being included into is frozen
75
75
  # so you cannot set or modify any instance variables
76
- module Renderable
76
+ module Renderable #:nodoc:
77
77
  private
78
78
  def recompile?(path)
79
79
  true
@@ -84,7 +84,7 @@ if Rails::VERSION::STRING =~ /^2\.3\.0/ || Rails::VERSION::STRING =~ /^2\.[0-2]\
84
84
  module ActionView #:nodoc:
85
85
  class PathSet #:nodoc:
86
86
 
87
- class Path
87
+ class Path #:nodoc:
88
88
 
89
89
  # make it always return a refreshed template!
90
90
  def [](template_path)
data/lib/bolt/listener.rb CHANGED
@@ -14,7 +14,7 @@ module Bolt
14
14
  # find appropriate listener
15
15
  listener
16
16
 
17
- $stdout.puts "** Using #{listener.class} " if Bolt['verbose']
17
+ $stdout.puts "** Using #{listener.class} " if Bolt.verbose?
18
18
 
19
19
  # trap the INT signal
20
20
  add_sigint_handler
@@ -59,11 +59,11 @@ module Bolt
59
59
  if Bolt['listener'] and ['generic', 'osx'].include?(Bolt['listener'])
60
60
  self.selected= Bolt::Listeners::Generic.new if Bolt['listener'] == 'generic'
61
61
  self.selected= Bolt::Listeners::Osx.new if Bolt['listener'] == 'osx'
62
- $stdout.puts "** Found listener setting in .bolt" if Bolt['verbose']
62
+ $stdout.puts "** Found listener setting in .bolt" if Bolt.verbose?
63
63
  return self.selected
64
64
  end
65
65
 
66
- $stdout.puts "** Determining listener..." if Bolt['verbose']
66
+ $stdout.puts "** Determining listener..." if Bolt.verbose?
67
67
 
68
68
  # TODO: os identification via RUBY_PLATFORM is flawed as it will return 'java' in jruby. Look for a different solution
69
69
  os_string = RUBY_PLATFORM.downcase
@@ -9,19 +9,22 @@ module Bolt
9
9
  class Generic
10
10
  attr_accessor :files, :interval, :busy, :notifier, :parent, :mappings
11
11
 
12
+ # constructor
12
13
  def initialize
13
14
  self.interval = 1 # decrease the CPU load by increasing the interval
14
15
  self.busy = false
15
16
  end
16
17
 
18
+ # find files and start the listener
17
19
  def start
18
- puts "** #{self.class} is scanning for files... " if Bolt['verbose']
20
+ puts "** #{self.class} is scanning for files... " if Bolt.verbose?
19
21
  # build a file collection
20
22
  find_files
21
23
  puts "** #{self.class} watching #{files.size} files... "
22
24
  wait
23
25
  end
24
26
 
27
+ # wait for a specified interval and check files for changes
25
28
  # source: ZenTest/autotest.rb
26
29
  def wait
27
30
  Kernel.sleep self.interval until check_files
@@ -32,12 +35,20 @@ module Bolt
32
35
  return if busy # if working on something already, skip the iteration
33
36
  updated = []
34
37
  files.each do |filename, mtime|
35
- current_mtime = File.stat(filename).mtime
38
+ begin
39
+ current_mtime = File.stat(filename).mtime
40
+ rescue Errno::ENOENT
41
+ # file was not found and was probably deleted
42
+ # remove the file from the file list
43
+ files.delete(filename)
44
+ puts "=> ERROR: #{filename} not found, ignoring" if Bolt.verbose?
45
+ next
46
+ end
36
47
  if current_mtime != mtime
37
48
  updated << filename
38
49
  # update the mtime in file registry so we it's only send once
39
50
  files[filename] = current_mtime
40
- $stdout.puts ">> Spotted change in #{filename}" if Bolt['verbose']
51
+ $stdout.puts ">> Spotted change in #{filename}" if Bolt.verbose?
41
52
  end
42
53
  end
43
54
  parent.handle(updated) if updated != []
@@ -55,15 +66,15 @@ module Bolt
55
66
  targets.each do |target|
56
67
  order = []
57
68
  Find.find(target) do |f|
58
-
59
69
  in_mappings = f =~ self.mappings
60
70
  next if in_mappings.nil?
61
71
  next if test ?d, f
62
72
  next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files
63
- next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files
73
+ next if f =~ /(\.svn|\.git)$/ # subversion/git
74
+ next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files
64
75
 
65
76
  filename = f.sub(/^\.\//, '')
66
-
77
+
67
78
  result[filename] = File.stat(filename).mtime rescue next
68
79
  end
69
80
  end
data/lib/bolt/notifier.rb CHANGED
@@ -9,26 +9,25 @@ module Bolt
9
9
 
10
10
  # Constructor
11
11
  def initialize
12
- # find appropriate notifier
12
+ # find an appropriate notifier
13
13
  notifier
14
14
  # present
15
- $stdout.puts "** Using #{notifier.class} \n" if Bolt['verbose']
15
+ $stdout.puts "** Using #{notifier.class} \n" if Bolt.verbose?
16
16
  end
17
17
 
18
- # Pick a listener to launch
18
+ # Pick a notifier to launch
19
19
  def notifier
20
20
  return selected if selected
21
21
 
22
-
23
22
  if Bolt['notifier'] and ['generic', 'growl'].include?(Bolt['notifier'])
24
23
  self.selected= Bolt::Notifiers::Growl.new if Bolt['notifier'] == 'growl'
25
24
  self.selected= Bolt::Notifiers::Generic.new if Bolt['notifier'] == 'generic'
26
25
  self.selected= Bolt::Notifiers::NotifyOsd.new if Bolt['notifier'] == 'notify_send'
27
- $stdout.puts "** Found 'notifier' setting in .bolt" if Bolt['verbose']
26
+ $stdout.puts "** Found 'notifier' setting in .bolt" if Bolt.verbose?
28
27
  return self.selected
29
28
  end
30
29
 
31
- $stdout.puts "** Determining notifier... \n" if Bolt['verbose']
30
+ $stdout.puts "** Determining notifier... \n" if Bolt.verbose?
32
31
 
33
32
  # default - growl (if growlnotify is present)
34
33
  output = %x[which growlnotify]
data/lib/bolt/runner.rb CHANGED
@@ -12,7 +12,7 @@ module Bolt
12
12
  # find appropriate runner
13
13
  runner
14
14
 
15
- $stdout.puts "** Using #{selected.class} \n" if Bolt['verbose']
15
+ $stdout.puts "** Using #{selected.class} \n" if Bolt.verbose?
16
16
  end
17
17
 
18
18
  # Pick a listener to launch
@@ -23,10 +23,10 @@ module Bolt
23
23
  self.selected= Bolt::Runners::TestUnit.new if Bolt['runner'] == 'test_unit'
24
24
  self.selected= Bolt::Runners::RSpec.new if Bolt['runner'] == 'rspec'
25
25
  self.selected= Bolt::Runners::Cucumber.new if Bolt['runner'] == 'cucumber'
26
- $stdout.puts "** Found 'runner' setting in .bolt" if Bolt['verbose']
26
+ $stdout.puts "** Found 'runner' setting in .bolt" if Bolt.verbose?
27
27
  return self.selected
28
28
  end
29
- $stdout.puts "** Determining runner... \n" if Bolt['verbose']
29
+ $stdout.puts "** Determining runner... \n" if Bolt.verbose?
30
30
  self.selected= Bolt::Runners::TestUnit.new
31
31
  self.selected= Bolt::Runners::RSpec.new if File.directory?('spec')
32
32
  self.selected
@@ -24,7 +24,7 @@ module Bolt
24
24
 
25
25
  reload filename
26
26
 
27
- puts "=> #{self.class} running test for #{filename}" if Bolt['verbose']
27
+ puts "=> #{self.class} running test for #{filename}" if Bolt.verbose?
28
28
  test_files = translate(filename)
29
29
 
30
30
  return if test_files == []
@@ -18,20 +18,24 @@ module Bolt
18
18
  # step mother storage
19
19
  @@mother = nil
20
20
 
21
+ # Save a reference for supplied StepMother
21
22
  def self.mother=(step_mother)
22
23
  @@mother = step_mother
23
24
  end
24
25
 
26
+ # Get the referenced StepMother
25
27
  def self.mother
26
28
  @@mother
27
29
  end
28
30
 
31
+ # Create a new Cucumber Runner
29
32
  def initialize
30
33
  self.controllers = {}
31
34
  self.models = {}
32
35
  read_map
33
36
  end
34
37
 
38
+ # Read the feature map located in .bolt file
35
39
  def read_map
36
40
  if !Bolt['feature_map']
37
41
  puts "** ERROR: could not find feature_map in .bolt"
@@ -66,7 +70,11 @@ module Bolt
66
70
  end
67
71
 
68
72
  end
69
- # mapping is a copied and modified version of mislav/rspactor Inspector#translate
73
+
74
+ # Translate a filename into an array of feature filenames
75
+ #
76
+ # This is a modified version of mislav/rspactor Inspector#translate
77
+ #
70
78
  def translate(file)
71
79
  self.heard = file
72
80
 
@@ -97,7 +105,8 @@ module Bolt
97
105
 
98
106
  end
99
107
 
100
- def run(files)
108
+ # Run an array of feature files
109
+ def run(features)
101
110
 
102
111
  # redirect spec output to StringIO
103
112
  io = StringIO.new
@@ -109,7 +118,7 @@ module Bolt
109
118
 
110
119
  Bolt::Runners::Cucumber.mother.reload_definitions! if Bolt::Runners::Cucumber.mother and self.heard.match('_steps.rb')
111
120
 
112
- ::Cucumber::Cli::Main.execute(files)
121
+ ::Cucumber::Cli::Main.execute(features)
113
122
 
114
123
  Bolt::Runners::Cucumber.mother.clear_steps_and_scenarios!
115
124
  # read the buffer
@@ -124,7 +133,7 @@ module Bolt
124
133
  last_three = last_three.gsub("\e[32m", '').gsub("\e[0m", '').gsub("\e[36m", '').gsub("\e[31m", '') # get ri of the color codes
125
134
 
126
135
  # sent result to notifier
127
- notifier.result(files.join(' '), last_three)
136
+ notifier.result(features.join(' '), last_three)
128
137
 
129
138
  end
130
139
 
@@ -133,13 +142,20 @@ module Bolt
133
142
  end
134
143
 
135
144
  # Cucumber hacks
145
+
146
+ # Load Cucumber requirements
136
147
  require 'cucumber'
137
- require 'cucumber/rspec_neuter'
148
+ begin
149
+ require 'cucumber/rspec_neuter'
150
+ rescue LoadError
151
+ puts '** ERROR: Could not load cucumber/rspec_neuter' if Bolt.verbose?
152
+ end
138
153
  require 'cucumber/cli/main'
139
154
 
140
- module Cucumber
141
- module StepMother
155
+ module Cucumber #:nodoc:
156
+ module StepMother #:nodoc:
142
157
 
158
+ # Clear the step definitions and reload them
143
159
  def reload_definitions!
144
160
  step_definitions.clear
145
161
  Dir['features/step_definitions/*'].map do |f|
@@ -148,15 +164,17 @@ module Cucumber
148
164
  end
149
165
  end
150
166
 
167
+ # Clear the steps and scenarios to always start fresh
151
168
  def clear_steps_and_scenarios!
152
169
  steps.clear
153
170
  scenarios.clear
154
171
  end
155
172
  end
156
173
 
157
- module Cli
158
- class Main
174
+ module Cli #:nodoc:
175
+ class Main #:nodoc:
159
176
 
177
+ # Overwritten execute to create a reference for StepMother
160
178
  def self.execute(args)
161
179
  instance = new(args)
162
180
  instance.execute!(@step_mother)
@@ -35,7 +35,10 @@ module Bolt
35
35
  Thread.current["test_runner_io"] = io
36
36
  end
37
37
 
38
- # mapping is a copied and modified version of mislav/rspactor Inspector#translate
38
+ # Translate a filename into a test filename
39
+ #
40
+ # This is a copied and modified version of mislav/rspactor Inspector#translate
41
+ #
39
42
  def translate(file)
40
43
 
41
44
  basename = File.basename(file)
@@ -67,12 +70,13 @@ module Bolt
67
70
  candidates << test_filename
68
71
  end
69
72
  if candidates == []
70
- puts "=> NOTICE: could not find test file for: #{file}" if Bolt['verbose']
73
+ puts "=> NOTICE: could not find test file for: #{file}" if Bolt.verbose?
71
74
  end
72
75
  # puts candidates.inspect
73
76
  candidates
74
77
  end
75
78
 
79
+ # Run the supplied files (tests)
76
80
  def run(files)
77
81
  file = files.first
78
82
  puts "** Running #{file}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marcinbunsch-bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Bunsch