2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-11-02 06:57:50 +08:00
|
|
|
module Autospec
|
|
|
|
class RspecRunner < BaseRunner
|
|
|
|
WATCHERS = {}
|
2018-12-04 11:48:13 +08:00
|
|
|
def self.watch(pattern, &blk)
|
|
|
|
WATCHERS[pattern] = blk
|
|
|
|
end
|
2023-12-15 23:46:04 +08:00
|
|
|
|
2018-12-04 11:48:13 +08:00
|
|
|
def watchers
|
|
|
|
WATCHERS
|
|
|
|
end
|
2013-11-02 06:57:50 +08:00
|
|
|
|
|
|
|
# Discourse specific
|
2023-01-21 02:52:49 +08:00
|
|
|
watch(%r{\Alib/(.+)\.rb\z}) { |m| "spec/components/#{m[1]}_spec.rb" }
|
2013-11-02 06:57:50 +08:00
|
|
|
|
2023-01-21 02:52:49 +08:00
|
|
|
watch(%r{\Aapp/(.+)\.rb\z}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
|
|
watch(%r{\Aapp/(.+)(\.erb|\.haml)\z}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
|
|
|
watch(%r{\Aspec/.+_spec\.rb\z})
|
|
|
|
watch(%r{\Aspec/support/.+\.rb\z}) { "spec" }
|
2018-08-22 12:35:57 +08:00
|
|
|
watch("app/controllers/application_controller.rb") { "spec/requests" }
|
|
|
|
|
|
|
|
watch(%r{app/controllers/(.+).rb}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
2013-11-02 06:57:50 +08:00
|
|
|
|
2023-01-21 02:52:49 +08:00
|
|
|
watch(%r{\Aapp/views/(.+)/.+\.(erb|haml)\z}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
2013-11-02 06:57:50 +08:00
|
|
|
|
2023-01-21 02:52:49 +08:00
|
|
|
watch(%r{\Aspec/fabricators/.+_fabricator\.rb\z}) { "spec" }
|
2013-11-02 06:57:50 +08:00
|
|
|
|
2023-01-21 02:52:49 +08:00
|
|
|
watch(%r{\Aapp/assets/javascripts/pretty-text/.*\.js\.es6\z}) do
|
|
|
|
"spec/components/pretty_text_spec.rb"
|
|
|
|
end
|
|
|
|
watch(%r{\Aplugins/.*/discourse-markdown/.*\.js\.es6\z}) do
|
2017-06-09 06:02:30 +08:00
|
|
|
"spec/components/pretty_text_spec.rb"
|
2023-01-09 20:10:19 +08:00
|
|
|
end
|
2017-06-09 06:02:30 +08:00
|
|
|
|
2023-01-21 02:52:49 +08:00
|
|
|
watch(%r{\Aplugins/.*/spec/.*\.rb})
|
|
|
|
watch(%r{\A(plugins/.*/)plugin\.rb}) { |m| "#{m[1]}spec" }
|
|
|
|
watch(%r{\A(plugins/.*)/(lib|app)}) { |m| "#{m[1]}/spec/integration" }
|
|
|
|
watch(%r{\A(plugins/.*)/lib/(.*)\.rb}) { |m| "#{m[1]}/spec/lib/#{m[2]}_spec.rb" }
|
2017-06-09 06:02:30 +08:00
|
|
|
|
2013-11-02 06:57:50 +08:00
|
|
|
RELOADERS = Set.new
|
2018-12-04 11:48:13 +08:00
|
|
|
def self.reload(pattern)
|
|
|
|
RELOADERS << pattern
|
|
|
|
end
|
2023-12-15 23:46:04 +08:00
|
|
|
|
2018-12-04 11:48:13 +08:00
|
|
|
def reloaders
|
|
|
|
RELOADERS
|
|
|
|
end
|
2013-11-02 06:57:50 +08:00
|
|
|
|
2017-10-06 13:20:01 +08:00
|
|
|
# we are using a simple runner at the moment, whole idea of using a reloader is no longer needed
|
|
|
|
watch("spec/rails_helper.rb")
|
|
|
|
watch(%r{config/.+\.rb})
|
|
|
|
#reload(%r{app/helpers/.+\.rb})
|
2013-11-02 06:57:50 +08:00
|
|
|
|
|
|
|
def failed_specs
|
|
|
|
specs = []
|
|
|
|
path = "./tmp/rspec_result"
|
|
|
|
specs = File.readlines(path) if File.exist?(path)
|
|
|
|
specs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|