guard-tap 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-tap.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{spec/spec_helper\.rb}) { 'spec' }
3
+ watch(%r{spec/.+_spec.rb})
4
+ watch(%r{lib/(.+).rb}) { |m| "spec/#{ m[1] }_spec.rb" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 hitode909
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,92 @@
1
+ # Guard::Tap
2
+
3
+ RSpec guard allows to automatically run TAP based test suites and print a report.
4
+
5
+ ## Installation
6
+
7
+ The simplest way to install Guard is to use [Bundler](http://gembundler.com/).
8
+ Please make sure to have [Guard](https://github.com/guard/guard) installed.
9
+
10
+ Add Guard::Tap to your `Gemfile`:
11
+
12
+ ```ruby
13
+ group :development do
14
+ gem 'guard-tap'
15
+ end
16
+ ```
17
+ Add the default Guard::Tap template to your `Guardfile` by running:
18
+
19
+ ```bash
20
+ $ guard init tap
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Please read [Guard usage doc](https://github.com/guard/guard#readme).
26
+
27
+ ## Guardfile
28
+
29
+ RSpec guard can be adapted to all kinds of projects.
30
+
31
+ ### Standard Perl project
32
+
33
+
34
+
35
+ ``` ruby
36
+ guard :tap, command: 'perl' do
37
+ watch %r{^t/.*\.t$}
38
+ end
39
+ ```
40
+ ### Detect the test files
41
+
42
+ You can watch `lib/` and detect the test file for the changed class.
43
+
44
+ ```ruby
45
+ guard :tap, command: 'perl' do
46
+ watch %r{^t/.*\.t$}
47
+ watch %r{^(lib/.*\.pm)$} do |m|
48
+ modified_file = m[0]
49
+
50
+ all_test_files = Dir.glob('t/**/**.t')
51
+
52
+ all_test_files.sort_by{ |test_file|
53
+ # sort by similarity of path
54
+ a = test_file
55
+ b = modified_file
56
+ delimiter = %r{[/_\-\.]}
57
+ a_fragments = a.split(delimiter)
58
+ b_fragments = b.split(delimiter)
59
+ (a_fragments + b_fragments).uniq.length.to_f / (a_fragments + b_fragments).length.to_f
60
+ }.first
61
+ end
62
+ end
63
+ ```
64
+
65
+ ## Options
66
+
67
+ You can pass the command to execute test file using the `:command` option:
68
+ By default, Guard::Tap just execute the file.
69
+
70
+ If you are using carton, set `carton exec -- perl` to command.
71
+
72
+ ``` ruby
73
+ guard :tap, command: 'carton exec -- perl' do
74
+ watch %r{^t/.*\.t$}
75
+ end
76
+ ```
77
+
78
+ ## Notification
79
+
80
+ Guard::Tap parses TAP output and notifify error messages when the tests are failed.
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
89
+
90
+ ## See also
91
+
92
+ - [Test Anything Protocol](http://testanything.org/)
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
data/guard-tap.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/tap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "guard-tap"
8
+ spec.version = Guard::TapVersion::VERSION
9
+ spec.authors = ["hitode909"]
10
+ spec.email = ["hitode909@gmail.com"]
11
+ spec.description = %q{Guard::Tap automatically run your tests using TAP(Test Anything Protocol).}
12
+ spec.summary = %q{Guard gem for Test Anything Protocol)}
13
+ spec.homepage = "http://github.com/hitode909/guard-tap"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency 'guard', '>= 1.8'
24
+
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'guard-rspec'
27
+ spec.add_development_dependency 'rspec'
28
+ end
@@ -0,0 +1,65 @@
1
+ module Guard
2
+ class Tap
3
+ module Runner
4
+ class << self
5
+
6
+ def run command, title = command
7
+ notify "runnning: #{title}"
8
+
9
+ now_error = false
10
+ error_message = ''
11
+ flush_error = lambda {
12
+ next unless error_message.length > 0
13
+ notify_error error_message
14
+ error_message = ''
15
+ }
16
+
17
+ IO.popen(command, "r+"){ |io|
18
+ while line = io.gets
19
+ UI.info line
20
+ if line =~ /^ok/
21
+ now_error = false
22
+ flush_error.call
23
+ elsif line =~ /^\d+.{2}\d+$/
24
+ now_error = false
25
+ flush_error.call
26
+ elsif line =~ /^not ok/
27
+ flush_error.call
28
+ now_error = true
29
+ end
30
+ if now_error
31
+ error_message << line
32
+ end
33
+ end
34
+ }
35
+ flush_error.call
36
+
37
+ if $?.success?
38
+ notify_success "success: #{title}"
39
+ else
40
+ notify_error "failed: #{title}"
41
+ end
42
+
43
+ $?.success?
44
+ rescue SystemCallError
45
+ notify_error "failed: #{title}"
46
+ false
47
+ end
48
+
49
+ def notify message, args = { }
50
+ ::Guard::UI.info message
51
+ ::Guard::Notifier.notify message, args
52
+ end
53
+
54
+ def notify_success message
55
+ notify message, image: :success
56
+ end
57
+
58
+ def notify_error message
59
+ notify message, image: :failed
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,18 @@
1
+ guard :tap, command: 'perl' do
2
+ watch %r{^t/.*\.t$}
3
+ watch %r{^(lib/.*\.pm)$} do |m|
4
+ modified_file = m[0]
5
+
6
+ all_test_files = Dir.glob('t/**/**.t')
7
+
8
+ all_test_files.sort_by{ |test_file|
9
+ # sort by similarity of path
10
+ a = test_file
11
+ b = modified_file
12
+ delimiter = %r{[/_\-\.]}
13
+ a_fragments = a.split(delimiter)
14
+ b_fragments = b.split(delimiter)
15
+ (a_fragments + b_fragments).uniq.length.to_f / (a_fragments + b_fragments).length.to_f
16
+ }.first
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module TapVersion
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
data/lib/guard/tap.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "guard/tap/version"
2
+
3
+ require 'guard'
4
+ require 'guard/guard'
5
+ require 'guard/watcher'
6
+
7
+ require 'shellwords'
8
+
9
+ module Guard
10
+ class Tap < Guard
11
+
12
+ autoload :Runner, 'guard/tap/runner'
13
+
14
+ def run_on_changes paths
15
+ paths.each{ |path|
16
+ Runner.run make_command(path), path
17
+ }
18
+ end
19
+
20
+ def make_command path
21
+ if options[:command]
22
+ "#{options[:command]} #{Shellwords.escape path} 2>&1"
23
+ else
24
+ "#{Shellwords.escape path} 2>&1"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Tap::Runner do
4
+
5
+ let(:runner) { Guard::Tap::Runner }
6
+
7
+ before do
8
+ runner.stub(:notify)
9
+ end
10
+
11
+ describe '#run' do
12
+ it 'returns true when success' do
13
+ runner.run('pwd').should == true
14
+ end
15
+
16
+ it 'returns false when failed' do
17
+ runner.run('undefined_method').should == false
18
+ end
19
+ end
20
+
21
+ describe '#notify' do
22
+ before do
23
+ runner.unstub(:notify)
24
+ end
25
+
26
+ it 'calls UI and Notifier' do
27
+ Guard::UI.should_receive(:info).with('hi')
28
+ Guard::Notifier.should_receive(:notify).with('hi', foo: 'bar')
29
+ runner.notify 'hi', foo: 'bar'
30
+ end
31
+ end
32
+
33
+ describe '#notify_success' do
34
+ it 'calls notify with image: success' do
35
+ runner.should_receive(:notify).with('hi', image: :success)
36
+ runner.notify_success('hi')
37
+ end
38
+ end
39
+
40
+ describe '#notify_error' do
41
+ it 'calls notify with image: failed' do
42
+ runner.should_receive(:notify).with('hi', image: :failed)
43
+ runner.notify_error('hi')
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Tap do
4
+
5
+ let(:guard) { Guard::Tap.new }
6
+
7
+ let(:runner) { Guard::Tap::Runner }
8
+
9
+ before do
10
+ runner.stub(:run)
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it 'has empty option' do
15
+ guard.options.should == { }
16
+ end
17
+ end
18
+
19
+ describe '#run_on_changes' do
20
+ it 'starts the Runner with the changed file' do
21
+ runner.should_receive(:run).with('test.pl 2>&1', 'test.pl').ordered
22
+ guard.run_on_changes(['test.pl'])
23
+ end
24
+
25
+ it 'starts the Runner with the each changed files' do
26
+ runner.should_receive(:run).with('test1.pl 2>&1', 'test1.pl').ordered
27
+ runner.should_receive(:run).with('test2.pl 2>&1', 'test2.pl').ordered
28
+ guard.run_on_changes(['test1.pl', 'test2.pl'])
29
+ end
30
+ end
31
+
32
+ describe '#make_command' do
33
+ it 'makes the shell command for Runner' do
34
+ guard.make_command('test.pl').should == 'test.pl 2>&1'
35
+ end
36
+
37
+ it 'escapes path' do
38
+ guard.make_command('the test.pl').should == 'the\ test.pl 2>&1'
39
+ end
40
+
41
+ context 'with the :command option' do
42
+ let(:guard) { Guard::Tap.new(nil, :command => 'perl') }
43
+
44
+ it 'makes the command with specified command' do
45
+ guard.make_command('test.pl').should == 'perl test.pl 2>&1'
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspec'
2
+ require 'guard/tap'
3
+
4
+ RSpec.configure do |config|
5
+
6
+ config.before(:each) do
7
+ ENV["GUARD_ENV"] = 'test'
8
+ @project_path = Pathname.new(File.expand_path('../../', __FILE__))
9
+
10
+ Guard::UI.stub(:info)
11
+ Guard::UI.stub(:debug)
12
+ Guard::UI.stub(:error)
13
+ Guard::UI.stub(:success)
14
+ Guard::UI.stub(:warning)
15
+ Guard::UI.stub(:notify)
16
+ end
17
+
18
+ config.after(:each) do
19
+ ENV["GUARD_ENV"] = nil
20
+ end
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-tap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - hitode909
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '1.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
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: guard-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
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Guard::Tap automatically run your tests using TAP(Test Anything Protocol).
111
+ email:
112
+ - hitode909@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - Guardfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - guard-tap.gemspec
124
+ - lib/guard/tap.rb
125
+ - lib/guard/tap/runner.rb
126
+ - lib/guard/tap/templates/Guardfile
127
+ - lib/guard/tap/version.rb
128
+ - spec/guard/tap/runner_spec.rb
129
+ - spec/guard/tap_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: http://github.com/hitode909/guard-tap
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ segments:
145
+ - 0
146
+ hash: 930200120556476862
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ segments:
154
+ - 0
155
+ hash: 930200120556476862
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.25
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Guard gem for Test Anything Protocol)
162
+ test_files:
163
+ - spec/guard/tap/runner_spec.rb
164
+ - spec/guard/tap_spec.rb
165
+ - spec/spec_helper.rb