Class: Guard::RSpec::Dsl

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

Instance Method Summary collapse

Constructor Details

#initialize(dsl) ⇒ Dsl


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

def initialize(dsl)
  @dsl = dsl
end

Instance Method Details

#rails(options = {}) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/guard/rspec/dsl.rb', line 33

def rails(options = {})
  # Rails example
  @rails ||= OpenStruct.new.tap do |rails|
    exts = options.dup.delete(:view_extensions) || %w(erb haml slim)

    rails.app_files = %r{^app/(.+)\.rb$}

    rails.views = %r{^app/(views/.+/[^/]*\.(?:#{exts * "|"}))$}
    rails.view_dirs = %r{^app/views/(.+)/[^/]*\.(?:#{exts * "|"})$}
    rails.layouts = %r{^app/layouts/(.+)/.*\.("#{exts * "|"}")$}

    rails.controllers = %r{^app/controllers/(.+)_controller\.rb$}
    rails.routes = "config/routes.rb"
    rails.app_controller = "app/controllers/application_controller.rb"
    rails.spec_helper = "#{rspec.spec_dir}/rails_helper.rb"
  end
end

#rspecObject


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

def rspec
  @rspec ||= OpenStruct.new(to_s: "spec").tap do |rspec|
    rspec.spec_dir = "spec"
    rspec.spec = ->(m) { "#{rspec.spec_dir}/#{m}_spec.rb" }
    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


26
27
28
29
30
31
# File 'lib/guard/rspec/dsl.rb', line 26

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.(m[1]) }
end