guard-cane 0.1.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - ruby-head
5
+ matrix:
6
+ allow_failures:
7
+ - rvm: ruby-head
8
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard :cane, cli: "--color" do
8
+ watch(/.*\.rb/)
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Justin Campbell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Guard::Cane
2
+ [![Build Status](https://secure.travis-ci.org/justincampbell/guard-cane.png)](https://secure.travis-ci.org/justincampbell/guard-cane)
3
+ [![Gem Version](https://badge.fury.io/rb/guard-cane.png)](http://badge.fury.io/rb/guard-cane)
4
+
5
+ Guard::Cane automatically runs [Cane](https://github.com/square/cane#usage)
6
+ when files change.
7
+
8
+ ## Installation
9
+
10
+ Put this in your Gemfile:
11
+
12
+ ```rb
13
+ gem 'guard-cane'
14
+ ```
15
+
16
+ And then install with:
17
+
18
+ ```sh
19
+ $ bundle
20
+ $ guard init cane
21
+ ```
22
+
23
+ This will place the following in your Guardfile:
24
+
25
+ ```rb
26
+ guard :cane, cli: "--color" do
27
+ watch(/.*\.rb/)
28
+ end
29
+ ```
30
+
31
+ Also recommended is adding a `.cane` file to your project. See
32
+ [square/cane](https://github.com/square/cane#usage) for details.
33
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cane/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ task default: :ci
6
+
7
+ task :ci do
8
+ Rake::Task["spec"].invoke
9
+ Rake::Task["cane"].invoke
10
+ end
11
+
12
+ Cane::RakeTask.new
13
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'guard-cane'
7
+ gem.version = '0.1.0.pre'
8
+ gem.authors = ["Justin Campbell"]
9
+ gem.email = ["justin@justincampbell.me"]
10
+ gem.summary = "Guard plugin for Cane"
11
+ gem.description = "Guard::Cane automatically runs Cane when files change"
12
+ gem.homepage = "https://github.com/justincampbell/guard-cane"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.require_paths = ["lib"]
16
+
17
+ gem.add_dependency 'cane'
18
+ gem.add_dependency 'guard'
19
+
20
+ gem.add_development_dependency 'guard-rspec'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ end
data/lib/guard/cane.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ # Defines the guard, which is automatically seen by Guard
6
+ class Cane < Guard
7
+ DEFAULTS = {
8
+ run_all_on_start: true
9
+ }
10
+
11
+ SUCCESS = ["Passed", { title: "Passed", image: :success }]
12
+ FAILED = ["Failed", { title: "Failed", image: :failed }]
13
+
14
+ attr_reader :last_result, :options
15
+
16
+ def initialize(watchers = [], options = {})
17
+ super
18
+
19
+ @options = DEFAULTS.merge(options)
20
+ end
21
+
22
+ def start
23
+ UI.info "Guard::Cane is running"
24
+
25
+ run_all if options[:run_all_on_start]
26
+ end
27
+
28
+ def run_all
29
+ cane
30
+ end
31
+
32
+ def run_on_changes(paths)
33
+ cane paths
34
+ end
35
+
36
+ def cane(paths = [])
37
+ command = build_command(paths)
38
+
39
+ UI.info "Running Cane: #{command}"
40
+
41
+ result = system command
42
+
43
+ if result
44
+ Notifier.notify(*SUCCESS) if last_result == false
45
+ else
46
+ Notifier.notify(*FAILED)
47
+ end
48
+
49
+ @last_result = result
50
+
51
+ result
52
+ end
53
+
54
+ def build_command(paths)
55
+ command = []
56
+
57
+ command << (options[:command] || "cane")
58
+
59
+ if paths.any?
60
+ joined_paths = paths.join(',')
61
+ command << "--all '{#{joined_paths}}'"
62
+ end
63
+
64
+ command << options[:cli]
65
+
66
+ command.compact.join(" ")
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ guard :cane, cli: "--color" do
2
+ watch(/.*\.rb/)
3
+ end
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Cane do
4
+ subject { guard }
5
+ let(:guard) { described_class.new(watchers, options) }
6
+
7
+ let(:options) { {} }
8
+ let(:paths) { [] }
9
+ let(:watchers) { [] }
10
+
11
+ before do
12
+ Guard::Notifier.stub :notify
13
+
14
+ Guard::UI.stub :info
15
+ Guard::UI.stub :error
16
+ end
17
+
18
+ describe "#start" do
19
+ subject(:start) { guard.start }
20
+
21
+ it "runs all" do
22
+ guard.should_receive :run_all
23
+
24
+ start
25
+ end
26
+
27
+ context "with run_all_on_start: false" do
28
+ let(:options) { { run_all_on_start: false } }
29
+
30
+ it "does not run all" do
31
+ guard.should_not_receive :run_all
32
+
33
+ start
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#run_all" do
39
+ subject(:run_all) { guard.run_all }
40
+
41
+ it "runs cane with no arguments" do
42
+ guard.should_receive(:cane).with()
43
+
44
+ run_all
45
+ end
46
+ end
47
+
48
+ describe "#run_on_changes" do
49
+ subject(:run_on_changes) { guard.run_on_changes(paths) }
50
+
51
+ let(:paths) { %w[a b c] }
52
+
53
+ it "runs cane with the paths" do
54
+ guard.should_receive(:cane).with(paths)
55
+
56
+ run_on_changes
57
+ end
58
+ end
59
+
60
+ describe "#cane" do
61
+ subject(:cane) { guard.cane(paths) }
62
+
63
+ let(:result) { true }
64
+
65
+ before do
66
+ guard.stub system: result
67
+ end
68
+
69
+ it { should be_true }
70
+
71
+ it "does not notify of success" do
72
+ Guard::Notifier.should_not_receive(:notify)
73
+
74
+ cane.should == true
75
+ end
76
+
77
+ context "when failed" do
78
+ let(:result) { false }
79
+
80
+ it { should be_false }
81
+
82
+ it "notifies of a failure" do
83
+ Guard::Notifier.should_receive(:notify).with(*described_class::FAILED)
84
+
85
+ cane
86
+ end
87
+ end
88
+
89
+ context "when failing and then succeeding" do
90
+ it "notifies of a success" do
91
+ guard.stub system: false
92
+ Guard::Notifier.should_receive(:notify).with(*described_class::FAILED)
93
+
94
+ guard.cane(paths)
95
+
96
+ guard.stub system: true
97
+ Guard::Notifier.should_receive(:notify).with(*described_class::SUCCESS)
98
+
99
+ guard.cane(paths)
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "#build_command" do
105
+ subject(:build_command) { guard.build_command(paths) }
106
+
107
+ it { should == "cane" }
108
+
109
+ context "with paths" do
110
+ let(:paths) { %w[a b c] }
111
+
112
+ it { should == "cane --all '{a,b,c}'" }
113
+ end
114
+
115
+ context "with cli arguments" do
116
+ let(:options) { { cli: "--color" } }
117
+
118
+ it { should == "cane --color" }
119
+ end
120
+
121
+ context "with a custom command" do
122
+ let(:options) { { command: "rake quality" } }
123
+
124
+ it { should == "rake quality" }
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,11 @@
1
+ ENV['RUBY_ENV'] ||= 'test'
2
+
3
+ require 'guard/cane'
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = :random
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-cane
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Justin Campbell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cane
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Guard::Cane automatically runs Cane when files change
95
+ email:
96
+ - justin@justincampbell.me
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - .travis.yml
104
+ - Gemfile
105
+ - Guardfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - guard-cane.gemspec
110
+ - lib/guard/cane.rb
111
+ - lib/guard/cane/templates/Guardfile
112
+ - spec/guard/cane_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: https://github.com/justincampbell/guard-cane
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>'
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.1
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.23
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Guard plugin for Cane
138
+ test_files: []
139
+ has_rdoc: