marcinbunsch-bolt 0.1.7 → 0.1.8

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/bin/bolt CHANGED
@@ -3,10 +3,11 @@ require 'rubygems'
3
3
  require 'bolt'
4
4
 
5
5
  # Rails support
6
+ # TODO test/test_helper is not good for checking for rails, try something else
6
7
  if File.exists?('test/test_helper.rb')
7
8
  require 'bolt/adapters/rails'
8
9
  end
9
10
 
10
11
 
11
- # start a listener
12
- Bolt::Listener.new
12
+ # start ## that must be the worst comment ever
13
+ Bolt.start
data/lib/bolt/listener.rb CHANGED
@@ -11,9 +11,8 @@ module Bolt
11
11
 
12
12
  # Constructor
13
13
  def initialize
14
- $stdout.puts "** Starting Bolt..."
15
14
  # find appropriate listener
16
- $stdout.puts "** Using #{listener.class}... "
15
+ $stdout.puts "** Using #{listener.class} "
17
16
 
18
17
  # trap the INT signal
19
18
  add_sigint_handler
data/lib/bolt/notifier.rb CHANGED
@@ -10,7 +10,7 @@ module Bolt
10
10
  # Constructor
11
11
  def initialize
12
12
  # find appropriate listener
13
- $stdout.puts "** Using #{notifier.class}... \n"
13
+ $stdout.puts "** Using #{notifier.class} \n"
14
14
 
15
15
  # launch appropriate listener
16
16
  # notifier.new
data/lib/bolt/runner.rb CHANGED
@@ -10,17 +10,24 @@ module Bolt
10
10
  # Constructor
11
11
  def initialize
12
12
  # find appropriate listener
13
- $stdout.puts "** Using #{runner.class}... \n"
13
+ runner
14
14
  end
15
15
 
16
16
  # Pick a listener to launch
17
17
  def runner
18
18
  return selected if selected
19
- # TODO: os identification via RUBY_PLATFORM is flawed as it will return 'java' in jruby. Look for a different solution
20
19
 
20
+ if Bolt['runner']
21
+ self.selected= Bolt::Runners::TestUnit.new if Bolt['runner'] == 'test_unit'
22
+ self.selected= Bolt::Runners::RSpec.new if Bolt['runner'] == 'rspec'
23
+ $stdout.puts "** Using #{selected.class} based on 'runner' setting in .bolt file \n"
24
+ return self.selected
25
+ end
26
+ $stdout.puts "** Determining runner... \n"
21
27
  self.selected= Bolt::Runners::TestUnit.new
22
- self.selected= Bolt::Runners::RSpec.new if File.directory?('spec')
23
- selected
28
+ self.selected= Bolt::Runners::RSpec.new if File.directory?('spec')
29
+ $stdout.puts "** Using #{selected.class} \n"
30
+ self.selected
24
31
  end
25
32
 
26
33
  end
@@ -23,19 +23,27 @@ module Bolt
23
23
  # force reload of file
24
24
  $".delete(filename)
25
25
  $".delete(File.join(Dir.pwd, filename))
26
-
27
- =begin
28
- # FIXME: This does not work well against a real project.
29
- klassname = filename.sub('app/controllers/', '').sub('app/models/', '').sub('lib/', '')
30
- test_class = klassname.sub('.rb', '').gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
31
- root_klass = test_class.split('::').first
26
+ file = filename
27
+ # reload tests and classes
28
+ if file.match(/(app\/controllers|app\/models|lib\/)/)
29
+ puts '=================='
30
+ klassname = file.sub('app/controllers/', '').sub('app/models/', '').sub('lib/', '')
31
+ klass_to_be_tested = klassname.sub('.rb', '').gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
32
+
33
+
34
+ # remove all methods - don't worry, the reload will bring them back refreshed
35
+ begin
36
+ klass = eval(klass_to_be_tested)
37
+ klass.instance_methods.each { |m|
38
+ begin
39
+ klass.send(:remove_method, m)
40
+ rescue
41
+ end
42
+ }
43
+ rescue NameError
44
+ end
45
+ end
32
46
 
33
- # remove the top constant/class from memory
34
- # this is required to rebuild classes before test run
35
- # one limitation - Spec/Test cannot be reloaded or it will crash
36
- Object.send(:remove_const, root_klass) unless root_klass == 'Spec' or root_klass == 'Test'
37
- =end
38
-
39
47
  if filename.include?('app/controllers') or filename.include?('app/models') or filename.include?('lib/')
40
48
  begin
41
49
  require File.join(Dir.pwd, filename)
@@ -157,9 +157,15 @@ module Bolt
157
157
  require file
158
158
  rescue LoadError
159
159
  notifier.error("Error in #{file}", $!)
160
+ puts $!
160
161
  return
161
162
  rescue ArgumentError
162
163
  notifier.error("Error in #{file}", $!)
164
+ puts $!
165
+ return
166
+ rescue SyntaxError
167
+ notifier.error("Error in #{file}", $!)
168
+ puts $!
163
169
  return
164
170
  end
165
171
 
data/lib/bolt.rb CHANGED
@@ -1,5 +1,42 @@
1
+ require 'yaml'
1
2
  # Why Bolt? Cause it's a cool name, that's why :)
2
3
  module Bolt
4
+
5
+ # static location for settings
6
+ @@config = {}
7
+
8
+ # set a config setting
9
+ def self.set(key, value)
10
+ @@config[key] = value
11
+ end
12
+
13
+ # retrieve a value for a config setting
14
+ def self.get(key)
15
+ @@config[key]
16
+ end
17
+
18
+ # convienience accessor
19
+ def self.[](key)
20
+ @@config[key]
21
+ end
22
+
23
+ # read the .bolt file for configuration
24
+ def self.read_dotfile
25
+ if File.exists?('.bolt')
26
+ $stdout.puts "** Found .bolt file"
27
+ @@config.merge!(YAML.load_file('.bolt'))
28
+ end
29
+ end
30
+
31
+ def self.start
32
+ $stdout.puts "** Starting Bolt..."
33
+
34
+ # read the dotfile
35
+ Bolt.read_dotfile
36
+
37
+ Bolt::Listener.new
38
+ end
39
+
3
40
  autoload :Mapper, 'bolt/mapper'
4
41
  autoload :Runner, 'bolt/runner'
5
42
  autoload :Notifier, 'bolt/notifier'
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.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Bunsch