guard-rspec 0.1.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Thibaud Guillaume-Gentil
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Guard::RSpec
2
+
3
+ Documentation is coming.
@@ -0,0 +1,24 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class RSpec < Guard
6
+
7
+ autoload :Runner, 'guard/rspec/runner'
8
+ autoload :Inspector, 'guard/rspec/inspector'
9
+
10
+ def start
11
+ Runner.set_rspec_version(options)
12
+ end
13
+
14
+ def run_all
15
+ Runner.run ["spec"], :message => "Running all specs"
16
+ end
17
+
18
+ def run_on_change(paths)
19
+ paths = Inspector.clean(paths)
20
+ Runner.run(paths) unless paths.empty?
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module Formatter
2
+
3
+ def guard_message(example_count, failure_count, pending_count, duration)
4
+ message = "#{example_count} examples, #{failure_count} failures"
5
+ if pending_count > 0
6
+ message << " (#{pending_count} pending)"
7
+ end
8
+ message << "\nin #{duration} seconds"
9
+ message
10
+ end
11
+
12
+ # failed | pending | success
13
+ def guard_image(failure_count, pending_count)
14
+ icon = if failure_count > 0
15
+ :failed
16
+ elsif pending_count > 0
17
+ :pending
18
+ else
19
+ :success
20
+ end
21
+ end
22
+
23
+ def notify(message, image)
24
+ Guard::Notifier.notify(message, :title => "RSpec results", :image => image)
25
+ end
26
+
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec/runner/formatter/base_formatter'
2
+ require "#{File.dirname(__FILE__)}/../formatter"
3
+ require "#{File.dirname(__FILE__)}/../../rspec"
4
+
5
+ class RSpec1 < Spec::Runner::Formatter::BaseFormatter
6
+ include Formatter
7
+
8
+ def dump_summary(duration, total, failures, pending)
9
+ message = guard_message(total, failures, pending, duration)
10
+ image = guard_image(failures, pending)
11
+ notify(message, image)
12
+ end
13
+
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+ require "#{File.dirname(__FILE__)}/../formatter"
3
+ require "#{File.dirname(__FILE__)}/../../rspec"
4
+
5
+ class RSpec2 < RSpec::Core::Formatters::ProgressFormatter
6
+ include Formatter
7
+
8
+ def dump_summary(duration, total, failures, pending)
9
+ super # needed to keep progress formatter
10
+
11
+ message = guard_message(total, failures, pending, duration)
12
+ image = guard_image(failures, pending)
13
+ notify(message, image)
14
+ end
15
+
16
+ end
@@ -0,0 +1,41 @@
1
+ module Guard
2
+ class RSpec
3
+ module Inspector
4
+ class << self
5
+
6
+ def clean(paths)
7
+ paths.uniq!
8
+ paths.compact!
9
+ paths = paths.select { |p| spec_file?(p) || spec_folder?(p) }
10
+ paths = paths.delete_if { |p| included_in_other_path?(p, paths) }
11
+ clear_spec_files_list
12
+ paths
13
+ end
14
+
15
+ private
16
+
17
+ def spec_folder?(path)
18
+ path.match(/^\/?spec/) && !path.match(/\..+$/)
19
+ end
20
+
21
+ def spec_file?(path)
22
+ spec_files.include?(path)
23
+ end
24
+
25
+ def spec_files
26
+ @spec_files ||= Dir.glob("spec/**/*_spec.rb")
27
+ end
28
+
29
+ def clear_spec_files_list
30
+ @spec_files = nil
31
+ end
32
+
33
+ def included_in_other_path?(path, paths)
34
+ paths = paths.select { |p| p != path }
35
+ paths.any? { |p| path.include?(p) && (path.gsub(p, '')).include?("/") }
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,55 @@
1
+ module Guard
2
+ class RSpec
3
+ module Runner
4
+ class << self
5
+ attr_reader :rspec_version
6
+
7
+ def run(paths, options = {})
8
+ message = options[:message] || "Running: #{paths.join(' ') }"
9
+ UI.info message, :reset => true
10
+ system(rspec_command(paths))
11
+ end
12
+
13
+ def set_rspec_version(options = {})
14
+ @rspec_version = options[:version] || determine_rspec_version
15
+ end
16
+
17
+ private
18
+
19
+ def rspec_command(paths)
20
+ cmd_parts = []
21
+ cmd_parts << "bundle exec" if bundler?
22
+ case rspec_version
23
+ when 1
24
+ cmd_parts << "spec"
25
+ cmd_parts << "-f progress --require #{File.dirname(__FILE__)}/formatter/rspec1.rb --format RSpec1:STDOUT"
26
+ when 2
27
+ cmd_parts << "rspec"
28
+ cmd_parts << "--require #{File.dirname(__FILE__)}/formatter/rspec2.rb --format RSpec2"
29
+ end
30
+ cmd_parts << "--color"
31
+ cmd_parts << paths.join(' ')
32
+ cmd_parts.join(" ")
33
+ end
34
+
35
+ def bundler?
36
+ @bundler ||= File.exist?("#{Dir.pwd}/Gemfile")
37
+ end
38
+
39
+ def determine_rspec_version
40
+ UI.info "Determine rspec_version... (can be forced with Guard::RSpec version option)"
41
+ if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
42
+ File.new("#{Dir.pwd}/spec/spec_helper.rb").read.include?("Spec::Runner") ? 1 : 2
43
+ elsif bundler?
44
+ # Allow RSpactor to be tested with RSpactor (bundle show inside a bundle exec)
45
+ ENV['BUNDLE_GEMFILE'] = "#{Dir.pwd}/Gemfile"
46
+ `bundle show rspec`.include?("/rspec-1.") ? 1 : 2
47
+ else
48
+ 2
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class RSpec
3
+ VERSION = "0.1.0.beta.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-rspec
3
+ version: !ruby/object:Gem::Version
4
+ hash: 62196401
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ - beta
11
+ - 1
12
+ version: 0.1.0.beta.1
13
+ platform: ruby
14
+ authors:
15
+ - Thibaud Guillaume-Gentil
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-10-03 00:00:00 +02:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: guard
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 62196401
32
+ segments:
33
+ - 0
34
+ - 1
35
+ - 0
36
+ - beta
37
+ - 1
38
+ version: 0.1.0.beta.1
39
+ type: :runtime
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ hash: 19
50
+ segments:
51
+ - 1
52
+ - 0
53
+ - 2
54
+ version: 1.0.2
55
+ type: :development
56
+ version_requirements: *id002
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ prerelease: false
60
+ requirement: &id003 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ hash: 62196431
66
+ segments:
67
+ - 2
68
+ - 0
69
+ - 0
70
+ - beta
71
+ - 22
72
+ version: 2.0.0.beta.22
73
+ type: :development
74
+ version_requirements: *id003
75
+ - !ruby/object:Gem::Dependency
76
+ name: guard
77
+ prerelease: false
78
+ requirement: &id004 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ hash: 62196401
84
+ segments:
85
+ - 0
86
+ - 1
87
+ - 0
88
+ - beta
89
+ - 1
90
+ version: 0.1.0.beta.1
91
+ type: :development
92
+ version_requirements: *id004
93
+ description: Guard::RSpec automatically run your specs (much like autotest)
94
+ email:
95
+ - thibaud@thibaud.me
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - lib/guard/rspec/formatter/rspec1.rb
104
+ - lib/guard/rspec/formatter/rspec2.rb
105
+ - lib/guard/rspec/formatter.rb
106
+ - lib/guard/rspec/inspector.rb
107
+ - lib/guard/rspec/runner.rb
108
+ - lib/guard/rspec/version.rb
109
+ - lib/guard/rspec.rb
110
+ - LICENSE
111
+ - README.rdoc
112
+ has_rdoc: true
113
+ homepage: http://rubygems.org/gems/guard-rspec
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 23
136
+ segments:
137
+ - 1
138
+ - 3
139
+ - 6
140
+ version: 1.3.6
141
+ requirements: []
142
+
143
+ rubyforge_project: guard-rspec
144
+ rubygems_version: 1.3.7
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: Guard gem for RSpec
148
+ test_files: []
149
+