Class: Guard::RSpec::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/rspec/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dsl) ⇒ Dsl

Returns a new instance of Dsl.



8
9
10
# File 'lib/guard/rspec/dsl.rb', line 8

def initialize(dsl)
  @dsl = dsl
end

Class Method Details

.detect_spec_file_for(rspec, file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/guard/rspec/dsl.rb', line 16

def self.detect_spec_file_for(rspec, file)
  # TODO: when spec not found ... run specs in topmost found path?
  # Or show warning?

  path = "#{rspec.spec_dir}/#{file}_spec.rb"
  return path unless file.start_with?("lib/")
  return path if Dir.exist?("#{rspec.spec_dir}/lib")

  without_lib = file.sub(%r{^lib/}, "")
  "#{rspec.spec_dir}/#{without_lib}_spec.rb"
end

Instance Method Details

#rails(options = {}) ⇒ Object



45
46
47
48
# File 'lib/guard/rspec/dsl.rb', line 45

def rails(options = {})
  # Rails example
  @rails ||= _build_rails_rules(_view_extensions(options) * "|")
end

#rspecObject



28
29
30
31
32
33
34
35
36
# File 'lib/guard/rspec/dsl.rb', line 28

def rspec
  @rspec ||= OpenStruct.new(to_s: "spec").tap do |rspec|
    rspec.spec_dir = "spec"
    rspec.spec = ->(m) { Dsl.detect_spec_file_for(rspec, m) }
    rspec.spec_helper = "#{rspec.spec_dir}/spec_helper.rb"
    rspec.spec_files = %r{^#{rspec.spec_dir}/.+_spec\.rb$}
    rspec.spec_support = %r{^#{rspec.spec_dir}/support/(.+)\.rb$}
  end
end

#rubyObject



38
39
40
41
42
43
# File 'lib/guard/rspec/dsl.rb', line 38

def ruby
  # Ruby apps
  @ruby ||= OpenStruct.new.tap do |ruby|
    ruby.lib_files = %r{^(lib/.+)\.rb$}
  end
end

#watch_spec_files_for(expr) ⇒ Object



12
13
14
# File 'lib/guard/rspec/dsl.rb', line 12

def watch_spec_files_for(expr)
  @dsl.send(:watch, expr) { |m| rspec.spec.call(m[1]) }
end