Class: Opal::RSpec::RakeTask
- Inherits:
-
Object
- Object
- Opal::RSpec::RakeTask
- Defined in:
- lib/opal/rspec-formatter/rake_task.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_load_path(expressions, server) ⇒ Object
- #get_custom_load_path_expressions ⇒ Object
- #get_default_teamcity_load_path_expressions ⇒ Object
-
#initialize(name = 'opal:rspec', &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
- #is_teamcity ⇒ Object
-
#orig_init ⇒ Object
Monkey patching the constructor without duplicating it here.
- #teamcity_require_indicator ⇒ Object
- #validate_teamcity_is_there(server) ⇒ Object
Constructor Details
#initialize(name = 'opal:rspec', &block) ⇒ RakeTask
Returns a new instance of RakeTask.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 51 def initialize(name = 'opal:rspec', &block) # We'll add our formatter set code before any main code that uses this task runs. This also should work # out of the box with opal-rails, which uses a different server.main util than others runner_block = lambda do |server| block[server] if block run_before_this = server.main # TODO: Surely a better way than environment variables to pass this on? ENV['opal_rspec_after_formatter_set'] = run_before_this server.main = 'opal/rspec/sprockets_runner_customformat' add_to_load_path get_custom_load_path_expressions, server if is_teamcity add_to_load_path get_default_teamcity_load_path_expressions, server validate_teamcity_is_there server end end orig_init name, &runner_block end |
Class Method Details
.get_requires ⇒ Object
7 8 9 10 11 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 7 def self.get_requires spec_opts = ENV['SPEC_OPTS'] return [] unless spec_opts spec_opts.scan(/--require (\S+)/).flatten end |
Instance Method Details
#add_to_load_path(expressions, server) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 20 def add_to_load_path(expressions, server) expressions.each do |r| matches = $:.select {|path| r.match(path)} matches.each do |load_path| puts "Adding #{load_path} to Opal path" server.append_path load_path end end end |
#get_custom_load_path_expressions ⇒ Object
13 14 15 16 17 18 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 13 def get_custom_load_path_expressions spec_opts = ENV['SPEC_OPTS'] return [] unless spec_opts matches = spec_opts.scan /--append_exp_from_load_path (\S+)/ matches.flatten.map {|m| Regexp.new(Regexp.escape(m))} end |
#get_default_teamcity_load_path_expressions ⇒ Object
30 31 32 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 30 def get_default_teamcity_load_path_expressions [/patch\/bdd/, /patch\/common/] end |
#is_teamcity ⇒ Object
38 39 40 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 38 def is_teamcity Opal::RSpec::RakeTask.get_requires.include? teamcity_require_indicator end |
#orig_init ⇒ Object
Monkey patching the constructor without duplicating it here
5 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 5 alias_method :orig_init, :initialize |
#teamcity_require_indicator ⇒ Object
34 35 36 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 34 def teamcity_require_indicator 'teamcity/spec/runner/formatter/teamcity/formatter' end |
#validate_teamcity_is_there(server) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/opal/rspec-formatter/rake_task.rb', line 42 def validate_teamcity_is_there(server) filename = teamcity_require_indicator+'.rb' paths = server.sprockets.paths found = paths.find {|p| File.exist?(File.join(p, filename))} unless found raise "TeamCity formatter require (#{filename}) supplied, but was not able to find Teamcity classes in Opal paths #{Opal.paths}. By default, anything in the Ruby load path that matches #{get_default_teamcity_load_path_expressions} will be used. If this needs to be changed, supply -- append_exp_from_load_path in the SPEC_OPTS env variable with another regex." end end |