Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework template using helpers + add template spec
- Loading branch information
Showing
3 changed files
with
132 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "ostruct" | ||
|
||
require "guard/rspec" | ||
|
||
module Guard | ||
class RSpec < Plugin | ||
class Dsl | ||
def initialize(dsl) | ||
@dsl = dsl | ||
end | ||
|
||
def watch_spec_files_for(expr) | ||
@dsl.send(:watch, expr) { |m| rspec.spec.(m[1]) } | ||
end | ||
|
||
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 | ||
|
||
def ruby | ||
# Ruby apps | ||
@ruby || OpenStruct.new.tap do |ruby| | ||
ruby.lib_files = %r{^(lib/.+)\.rb$} | ||
end | ||
end | ||
|
||
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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require "guard/compat/test/template" | ||
|
||
# Do not require to simulate Guardfile loading more accurately | ||
# require 'guard/rspec' | ||
|
||
RSpec.describe "Guard::RSpec" do | ||
describe "template" do | ||
subject { Guard::Compat::Test::Template.new("Guard::RSpec") } | ||
|
||
it "matches spec files by default" do | ||
expect(subject.changed("spec/lib/foo_spec.rb")). | ||
to eq(%w(spec/lib/foo_spec.rb)) | ||
|
||
expect(subject.changed("spec/spec_helper.rb")).to eq(%w(spec)) | ||
end | ||
|
||
it "matches Ruby files by default" do | ||
expect(subject.changed("lib/foo.rb")).to eq(%w(spec/lib/foo_spec.rb)) | ||
end | ||
|
||
it "matches Rails files by default" do | ||
expect(subject.changed("spec/rails_helper.rb")).to eq(%w(spec)) | ||
|
||
expect(subject.changed("app/models/foo.rb")). | ||
to eq(%w(spec/models/foo_spec.rb)) | ||
|
||
expect(subject.changed("app/views/foo/bar.slim")).to eq( | ||
%w( | ||
spec/views/foo/bar.slim_spec.rb | ||
spec/features/foo_spec.rb | ||
) | ||
) | ||
|
||
expect(subject.changed("app/controllers/application_controller.rb")). | ||
to eq( | ||
%w( | ||
spec/controllers/application_controller_spec.rb | ||
spec/routing/application_routing_spec.rb | ||
spec/acceptance/application_spec.rb | ||
spec/controllers | ||
) | ||
) | ||
|
||
expect(subject.changed("app/controllers/foo_controller.rb")). | ||
to match_array( | ||
%w( | ||
spec/controllers/foo_controller_spec.rb | ||
spec/routing/foo_routing_spec.rb | ||
spec/acceptance/foo_spec.rb | ||
) | ||
) | ||
|
||
expect(subject.changed("config/routes.rb")).to eq(%w(spec/routing)) | ||
end | ||
end | ||
end |