guard-motion 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ ## 0.1.2 - May 23, 2013
2
+
3
+ ### Improvements
4
+
5
+ - Use Inspector to handle paths better
6
+
7
+ ### Bug Fixes
8
+
9
+ - Switch to rake spec to support both RubyMotion iOS and OSX (by [@libin](https://github.com/libin))
10
+ - Fix Growl notifier error, updated specs to match (by [@philomory ](https://github.com/philomory))
11
+
1
12
  ## 0.1.1 - September 11, 2012
2
13
 
3
14
  ### Improvements
data/README.md CHANGED
@@ -52,7 +52,7 @@ end
52
52
  ``` ruby
53
53
  guard 'motion' do
54
54
  watch(%r{^spec/.+_spec\.rb$})
55
- watch(%r{^lib/[^/]+/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
55
+ watch(%r{^lib/[^/]+/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
56
56
  end
57
57
  ```
58
58
 
@@ -78,13 +78,14 @@ end
78
78
  ### List of available options:
79
79
 
80
80
  ``` ruby
81
- :bundler => false # use "bundle exec" to run the rake command, default: true
82
- :binstubs => true # use "bin/rake" to run the rake command (takes precedence over :bundle), default: false
83
- :notification => false # display Growl (or Libnotify) notification after the specs are done running, default: true
84
- :all_after_pass => false # run all specs after changed specs pass, default: true
85
- :all_on_start => false # run all the specs at startup, default: true
86
- :keep_failed => false # keep failed specs until they pass, default: true
87
- :spec_paths => ["spec"] # specify an array of paths that contain spec files
81
+ :bundler => false # use "bundle exec" to run the rake command, default: true
82
+ :binstubs => true # use "bin/rake" to run the rake command (takes precedence over :bundle), default: false
83
+ :env => {:output => 'test_unit'} # set env variables to be used by the RubyMotion spec runner, default: {}
84
+ :notification => false # display Growl (or Libnotify) notification after the specs are done running, default: true
85
+ :all_after_pass => false # run all specs after changed specs pass, default: true
86
+ :all_on_start => false # run all the specs at startup, default: true
87
+ :keep_failed => false # keep failed specs until they pass, default: true
88
+ :spec_paths => ["spec"] # specify an array of paths that contain spec files
88
89
  ```
89
90
 
90
91
  You can also use a custom binstubs directory using `:binstubs => 'some-dir'`.
@@ -7,6 +7,7 @@ module Guard
7
7
  class Motion < Guard
8
8
  autoload :ResultsParser, 'guard/motion/results_parser'
9
9
  autoload :Runner, 'guard/motion/runner'
10
+ autoload :Inspector, 'guard/motion/inspector'
10
11
 
11
12
  # Initialize a Guard.
12
13
  # @param [Array<Guard::Watcher>] watchers the Guard file watchers
@@ -23,6 +24,7 @@ module Guard
23
24
  @failed_paths = []
24
25
 
25
26
  @runner = Runner.new(@options)
27
+ @inspector = Inspector.new(@options)
26
28
  end
27
29
 
28
30
  # Call once when Guard starts. Please override initialize method to init stuff.
@@ -57,7 +59,7 @@ module Guard
57
59
  # @raise [:task_has_failed] when run_on_change has failed
58
60
  def run_on_changes(paths)
59
61
  paths += @failed_paths if @options[:keep_failed]
60
- paths.uniq!
62
+ paths = @inspector.clean(paths).uniq
61
63
 
62
64
  if passed = @runner.run(paths)
63
65
  remove_failed(paths)
@@ -0,0 +1,72 @@
1
+ module Guard
2
+ class Motion
3
+ class Inspector
4
+
5
+ def initialize(options = {})
6
+ self.excluded = options[:exclude]
7
+ self.spec_paths = options[:spec_paths]
8
+ end
9
+
10
+ def excluded
11
+ @excluded || []
12
+ end
13
+
14
+ def excluded=(pattern)
15
+ @excluded = Dir[pattern.to_s]
16
+ end
17
+
18
+ def spec_paths
19
+ @spec_paths || []
20
+ end
21
+
22
+ def spec_paths=(paths)
23
+ @spec_paths = Array(paths)
24
+ end
25
+
26
+ def clean(paths)
27
+ paths.uniq!
28
+ paths.compact!
29
+ clear_spec_files_list_after do
30
+ paths = paths.select { |path| should_run_spec_file?(path) }
31
+ end
32
+ paths.reject { |p| included_in_other_path?(p, paths) }
33
+ end
34
+
35
+ private
36
+
37
+ def should_run_spec_file?(path)
38
+ (spec_file?(path) || feature_file?(path) || spec_folder?(path)) && !excluded.include?(path)
39
+ end
40
+
41
+ def spec_file?(path)
42
+ spec_files.include?(path)
43
+ end
44
+
45
+ def feature_file?(path)
46
+ feature_files.include?(path)
47
+ end
48
+
49
+ def spec_folder?(path)
50
+ path.match(%r{^(#{spec_paths.join("|")})[^\.]*$})
51
+ end
52
+
53
+ def spec_files
54
+ @spec_files ||= spec_paths.collect { |path| Dir[File.join(path, "**{,/*/**}", "*_spec.rb")] }.flatten
55
+ end
56
+
57
+ def feature_files
58
+ @feature_files ||= spec_paths.collect { |path| Dir[File.join(path, "**{,/*/**}", "*.feature")] }.flatten
59
+ end
60
+
61
+ def clear_spec_files_list_after
62
+ yield
63
+ @spec_files = nil
64
+ end
65
+
66
+ def included_in_other_path?(path, paths)
67
+ (paths - [path]).any? { |p| path.include?(p) && path.sub(p, '').include?('/') }
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -7,6 +7,7 @@ module Guard
7
7
  @options = {
8
8
  :bundler => true,
9
9
  :binstubs => false,
10
+ :env => {},
10
11
  :notification => true,
11
12
  }.merge(options)
12
13
  end
@@ -43,7 +44,7 @@ module Guard
43
44
  type = :success
44
45
  end
45
46
 
46
- Notifier.notify(message, :type => type, :image => type, :title => 'RubyMotion Spec Results', :priority => 2)
47
+ Notifier.notify(message, :image => type, :title => 'RubyMotion Spec Results', :priority => 2)
47
48
  end
48
49
 
49
50
  def rake_executable
@@ -54,6 +55,11 @@ module Guard
54
55
 
55
56
  def rake_command(paths)
56
57
  cmd_parts = []
58
+
59
+ @options[:env].each do |var, value|
60
+ cmd_parts << "#{var}=#{value}"
61
+ end
62
+
57
63
  cmd_parts << "bundle exec" if bundle_exec?
58
64
  cmd_parts << rake_executable
59
65
  cmd_parts << "spec:specific[\"#{paths.join(';')}\"]"
@@ -15,7 +15,7 @@ if Kernel.const_defined?(:Rake)
15
15
  spec_files = App.config.spec_files.select{|file_path| !(file_path =~ /_spec.rb$/)}
16
16
  spec_files += files.split(';')
17
17
  App.config.instance_variable_set("@spec_files", spec_files)
18
- Rake::Task["simulator"].invoke
18
+ Rake::Task["spec"].invoke
19
19
  end
20
20
  end
21
21
  end
@@ -2,8 +2,8 @@ guard 'motion' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
 
4
4
  # RubyMotion App example
5
- watch(%r{^app/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
5
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
6
 
7
7
  # RubyMotion gem example
8
- watch(%r{^lib/[^/]+/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
8
+ watch(%r{^lib/[^/]+/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
9
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module MotionVersion
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ # Empty file to test spec_paths option
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Motion::Inspector do
4
+
5
+ describe '.initialize' do
6
+ it 'accepts an :exclude option that sets @excluded' do
7
+ inspector1 = described_class.new(:exclude => 'spec/slow/*')
8
+
9
+ inspector2 = described_class.new
10
+ inspector2.excluded = 'spec/slow/*'
11
+
12
+ inspector1.excluded.should eq inspector2.excluded
13
+ end
14
+
15
+ it 'accepts a :spec_paths option that sets @spec_paths' do
16
+ inspector1 = described_class.new(:spec_paths => ['spec/slow'])
17
+
18
+ inspector2 = described_class.new
19
+ inspector2.spec_paths = ['spec/slow']
20
+
21
+ inspector1.spec_paths.should eq inspector2.spec_paths
22
+ end
23
+ end
24
+
25
+ describe '#excluded=' do
26
+ it 'runs a glob on the given pattern' do
27
+ subject.excluded = 'spec/slow/*'
28
+ subject.excluded.should eq Dir['spec/slow/*']
29
+ end
30
+ end
31
+
32
+ describe '#spec_paths=' do
33
+ context 'given a string' do
34
+ before { subject.spec_paths = 'test' }
35
+
36
+ it 'returns an array' do
37
+ subject.spec_paths.should eq ['test']
38
+ end
39
+ end
40
+
41
+ context 'given an array' do
42
+ before { subject.spec_paths = ['test'] }
43
+
44
+ it 'returns an array' do
45
+ subject.spec_paths.should eq ['test']
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#clean' do
51
+ before do
52
+ subject.excluded = nil
53
+ subject.spec_paths = ['spec']
54
+ end
55
+
56
+ it 'removes non-spec files' do
57
+ subject.clean(['spec/guard/motion_spec.rb', 'bob.rb']).
58
+ should eq ['spec/guard/motion_spec.rb']
59
+ end
60
+
61
+ it 'removes spec-looking but non-existing files' do
62
+ subject.clean(['spec/guard/motion_spec.rb', 'bob_spec.rb']).
63
+ should eq ['spec/guard/motion_spec.rb']
64
+ end
65
+
66
+ it 'removes spec-looking but non-existing files (2)' do
67
+ subject.clean(['spec/guard/rspec/version_spec.rb']).should be_empty
68
+ end
69
+
70
+ it 'keeps spec folder path' do
71
+ subject.clean(['spec/guard/motion_spec.rb', 'spec/models']).
72
+ should eq ['spec/guard/motion_spec.rb', 'spec/models']
73
+ end
74
+
75
+ it 'removes duplication' do
76
+ subject.clean(['spec', 'spec']).should eq ['spec']
77
+ end
78
+
79
+ it 'removes spec folders included in other spec folders' do
80
+ subject.clean(['spec/models', 'spec']).should eq ['spec']
81
+ end
82
+
83
+ it 'removes spec files included in spec folders' do
84
+ subject.clean(['spec/guard/motion_spec.rb', 'spec']).should eq ['spec']
85
+ end
86
+
87
+ it 'removes spec files included in spec folders (2)' do
88
+ subject.clean([
89
+ 'spec/guard/motion_spec.rb', 'spec/guard/rspec/runner_spec.rb',
90
+ 'spec/guard/rspec'
91
+ ]).should eq ['spec/guard/motion_spec.rb', 'spec/guard/rspec']
92
+ end
93
+
94
+ it 'keeps top-level specs' do
95
+ subject.spec_paths = ['spec/fixtures/other_spec_path']
96
+ subject.clean(['spec/fixtures/other_spec_path/empty_spec.rb']).
97
+ should eq ['spec/fixtures/other_spec_path/empty_spec.rb']
98
+ end
99
+
100
+ it 'keeps spec files in symlink target' do
101
+ subject.clean(['spec/fixtures/symlink_to_spec/motion_spec.rb']).
102
+ should eq ['spec/fixtures/symlink_to_spec/motion_spec.rb']
103
+ end
104
+
105
+ describe 'excluded files' do
106
+ context 'with a path to a single spec' do
107
+ it 'ignores the one spec' do
108
+ subject.excluded = 'spec/guard/motion_spec.rb'
109
+ subject.clean(['spec/guard/motion_spec.rb']).should be_empty
110
+ end
111
+ end
112
+
113
+ context 'with a glob' do
114
+ it 'ignores files recursively' do
115
+ subject.excluded = 'spec/guard/**/*'
116
+ subject.clean(['spec/guard/motion_spec.rb', 'spec/guard/motion/runner_spec.rb']).should be_empty
117
+ end
118
+ end
119
+ end
120
+
121
+ describe 'spec paths' do
122
+ context 'with an expanded spec path' do
123
+ before { subject.spec_paths = ['spec', 'spec/fixtures/other_spec_path'] }
124
+
125
+ it 'should clean paths not specified' do
126
+ subject.clean([
127
+ 'clean_me/spec/cleaned_spec.rb', 'spec/guard/motion/runner_spec.rb',
128
+ 'spec/fixtures/other_spec_path/empty_spec.rb'
129
+ ]).should eq ['spec/guard/motion/runner_spec.rb', 'spec/fixtures/other_spec_path/empty_spec.rb']
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ end
@@ -54,7 +54,7 @@ module Guard
54
54
 
55
55
  it "sends a failure notification" do
56
56
  ::Guard::Notifier.should_receive(:notify).with(
57
- 'Failed', :title => 'RubyMotion Spec Results', :type => :failed, :image => :failed, :priority => 2
57
+ 'Failed', :title => 'RubyMotion Spec Results', :image => :failed, :priority => 2
58
58
  )
59
59
 
60
60
  subject.run(['spec'])
@@ -66,7 +66,7 @@ module Guard
66
66
 
67
67
  it "sends a spec failed notification" do
68
68
  ::Guard::Notifier.should_receive(:notify).with(
69
- '31 specs, 2 failures, 0 errors', :title => 'RubyMotion Spec Results', :type => :failed, :image => :failed, :priority => 2)
69
+ '31 specs, 2 failures, 0 errors', :title => 'RubyMotion Spec Results', :image => :failed, :priority => 2)
70
70
 
71
71
  subject.run(["spec"])
72
72
  end
@@ -77,7 +77,7 @@ module Guard
77
77
 
78
78
  it "sends a success notification" do
79
79
  ::Guard::Notifier.should_receive(:notify).with(
80
- '31 specs, 0 failures, 0 errors', :title => 'RubyMotion Spec Results', :type => :success, :image => :success, :priority => 2
80
+ '31 specs, 0 failures, 0 errors', :title => 'RubyMotion Spec Results', :image => :success, :priority => 2
81
81
  )
82
82
 
83
83
  subject.run(['spec'])
@@ -86,7 +86,6 @@ module Guard
86
86
  end
87
87
 
88
88
  describe 'options' do
89
-
90
89
  describe ':bundler' do
91
90
  context ':bundler => false' do
92
91
  subject { described_class.new(:bundler => false) }
@@ -139,6 +138,18 @@ module Guard
139
138
  end
140
139
  end
141
140
 
141
+ describe ':env' do
142
+ subject { described_class.new(:env => { :debug => 1, :output => "test_unit" }) }
143
+
144
+ it 'sets environment variables' do
145
+ PTY.should_receive(:spawn).with(
146
+ "debug=1 output=test_unit bundle exec rake spec:specific[\"spec\"]"
147
+ )
148
+
149
+ subject.run(['spec'])
150
+ end
151
+ end
152
+
142
153
  describe ':notification' do
143
154
  context ':notification => false' do
144
155
  subject { described_class.new(:notification => false) }
metadata CHANGED
@@ -1,109 +1,103 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-motion
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - mordaroso
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-11 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: guard
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 19
29
- segments:
30
- - 1
31
- - 1
32
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.1.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 25
45
- segments:
46
- - 0
47
- - 9
48
- version: "0.9"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0.9'
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: bundler
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0.9'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
55
49
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 19
60
- segments:
61
- - 1
62
- - 1
63
- - 0
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
64
53
  version: 1.1.0
65
54
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: rspec
69
55
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
71
57
  none: false
72
- requirements:
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
73
67
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 23
76
- segments:
77
- - 2
78
- - 10
79
- version: "2.10"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.10'
80
70
  type: :development
81
- version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
83
- name: guard-rspec
84
71
  prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
86
73
  none: false
87
- requirements:
74
+ requirements:
88
75
  - - ~>
89
- - !ruby/object:Gem::Version
90
- hash: 13
91
- segments:
92
- - 1
93
- - 1
94
- version: "1.1"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.10'
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: '1.1'
95
86
  type: :development
96
- version_requirements: *id005
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.1'
97
94
  description: Guard::Motion automatically run your specs (much like autotest).
98
- email:
95
+ email:
99
96
  - mordaroso@gmail.com
100
97
  executables: []
101
-
102
98
  extensions: []
103
-
104
99
  extra_rdoc_files: []
105
-
106
- files:
100
+ files:
107
101
  - .gitignore
108
102
  - .travis.yml
109
103
  - CHANGELOG.md
@@ -114,51 +108,47 @@ files:
114
108
  - Rakefile
115
109
  - guard-motion.gemspec
116
110
  - lib/guard/motion.rb
111
+ - lib/guard/motion/inspector.rb
117
112
  - lib/guard/motion/results_parser.rb
118
113
  - lib/guard/motion/runner.rb
119
114
  - lib/guard/motion/tasks.rb
120
115
  - lib/guard/motion/templates/Guardfile
121
116
  - lib/guard/motion/version.rb
122
117
  - spec/fixtures/bundler/Gemfile
118
+ - spec/fixtures/other_spec_path/empty_spec.rb
119
+ - spec/guard/motion/inspector_spec.rb
123
120
  - spec/guard/motion/results_parser_spec.rb
124
121
  - spec/guard/motion/runner_spec.rb
125
122
  - spec/guard/motion_spec.rb
126
123
  - spec/spec_helper.rb
127
124
  homepage: http://rubygems.org/gems/guard-motion
128
125
  licenses: []
129
-
130
126
  post_install_message:
131
127
  rdoc_options: []
132
-
133
- require_paths:
128
+ require_paths:
134
129
  - lib
135
- required_ruby_version: !ruby/object:Gem::Requirement
130
+ required_ruby_version: !ruby/object:Gem::Requirement
136
131
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
142
- - 0
143
- version: "0"
144
- required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
137
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
151
- - 0
152
- version: "0"
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
153
142
  requirements: []
154
-
155
143
  rubyforge_project:
156
- rubygems_version: 1.8.15
144
+ rubygems_version: 1.8.23
157
145
  signing_key:
158
146
  specification_version: 3
159
147
  summary: Guard gem for RubyMotion
160
- test_files:
148
+ test_files:
161
149
  - spec/fixtures/bundler/Gemfile
150
+ - spec/fixtures/other_spec_path/empty_spec.rb
151
+ - spec/guard/motion/inspector_spec.rb
162
152
  - spec/guard/motion/results_parser_spec.rb
163
153
  - spec/guard/motion/runner_spec.rb
164
154
  - spec/guard/motion_spec.rb