guard-jasmine-node 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ /.rvmrc
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ # travis-ci ftw
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-jasmine-node.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/jasmine_node/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-jasmine-node"
7
+ s.version = Guard::JasmineNodeVersion::VERSION
8
+ s.authors = ["dave@kapoq.com"]
9
+ s.email = ["dave@kapoq.com"]
10
+ s.homepage = "https://github.com/kapoq/guard-jasmine-node"
11
+ s.summary = %q{Guard::JasmineNode automatically runs your Jasmine Node specs when files are modified}
12
+ s.description = %q{}
13
+
14
+ s.rubyforge_project = "guard-jasmine-node"
15
+
16
+ s.add_dependency "guard", ">= 0.4"
17
+
18
+ s.add_development_dependency "rspec"
19
+ s.add_development_dependency "guard-rspec"
20
+ if RUBY_PLATFORM =~ /linux/
21
+ s.add_development_dependency "rb-inotify"
22
+ s.add_development_dependency "libnotify"
23
+ end
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,26 @@
1
+ require 'guard/jasmine_node'
2
+
3
+ Guard::Jasminenode = Guard::JasmineNode
4
+
5
+ module Guard
6
+ class Jasminenode < Guard
7
+ GEM_NAME = "jasmine-node"
8
+
9
+ # Guardfile template needed inside guard gem
10
+ def self.init(name)
11
+ if ::Guard::Dsl.guardfile_include?(GEM_NAME)
12
+ ::Guard::UI.info "Guardfile already includes #{GEM_NAME} guard"
13
+ else
14
+ content = File.read('Guardfile')
15
+ guard = File.read("#{::Guard.locate_guard(GEM_NAME)}/lib/guard/jasmine_node/templates/Guardfile")
16
+ File.open('Guardfile', 'wb') do |f|
17
+ f.puts(content)
18
+ f.puts("")
19
+ f.puts(guard)
20
+ end
21
+ ::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,70 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class JasmineNode < Guard
6
+ DEFAULT_OPTIONS = {
7
+ :jasmine_node_bin => "jasmine-node",
8
+ :all_after_pass => true,
9
+ :all_on_start => true,
10
+ :keep_failed => true
11
+ }
12
+
13
+ autoload :Runner, "guard/jasmine_node/runner"
14
+
15
+ def initialize(watchers = [], options = {})
16
+ super(watchers, DEFAULT_OPTIONS.merge(options))
17
+ clear_pass_state
18
+ end
19
+
20
+ def start
21
+ run_all if options[:all_on_start]
22
+ end
23
+
24
+ def run_all
25
+ outcome = Runner.run(["spec"], options.merge(:message => "Running all specs"))
26
+ set_pass_state(outcome)
27
+ end
28
+
29
+ def run_on_change(changed_paths = [])
30
+ run_paths = if options[:keep_failed]
31
+ failing_paths + changed_paths
32
+ else
33
+ changed_paths
34
+ end
35
+
36
+ outcome = Runner.run(run_paths, options)
37
+ set_pass_state(outcome, run_paths)
38
+
39
+ if passing?
40
+ run_all if options[:all_after_pass]
41
+ end
42
+ end
43
+
44
+ def passing?
45
+ @passing
46
+ end
47
+
48
+ def failing_paths
49
+ @failing_paths
50
+ end
51
+
52
+ private
53
+
54
+ def clear_pass_state
55
+ @passing = true
56
+ @failing_paths = []
57
+ end
58
+
59
+ def set_pass_state(passed, run_paths = [])
60
+ @passing = passed
61
+ if run_paths.any?
62
+ @failing_paths = if passing?
63
+ @failing_paths - run_paths
64
+ else
65
+ @failing_paths && run_paths
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,22 @@
1
+ require 'guard/ui'
2
+
3
+ module Guard
4
+ class JasmineNode
5
+ module Runner
6
+ def self.run(paths = [], options = {})
7
+ return false if paths.empty?
8
+
9
+ message = options.fetch(:message, "Running: #{paths.join(' ')}")
10
+ ::Guard::UI.info(message, :reset => true)
11
+
12
+ system(jasmine_node_command(paths, options))
13
+ end
14
+
15
+ private
16
+
17
+ def self.jasmine_node_command(paths = [], options = {})
18
+ "#{options[:jasmine_node_bin]} #{paths.join(' ')}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ guard "jasmine-node", :jasmine_node_bin => File.expand_path(File.dirname(__FILE__) + "/node_modules/jasmine-node/bin/jasmine-node") do
2
+ watch(%r{^spec/.+_spec\.js$})
3
+ watch(%r{^lib/(.+)\.js$}) { |m| "spec/lib/#{m[1]}_spec.js" }
4
+ watch('spec/spec_helper.js')
5
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module JasmineNodeVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::JasmineNode do
4
+ let(:guard) { Guard::JasmineNode.new }
5
+ let(:runner) { Guard::JasmineNode::Runner }
6
+
7
+ describe "#initialize" do
8
+ context "when no options are given" do
9
+ it "sets a default path to jasmine-node bin" do
10
+ guard.options[:jasmine_node_bin].should eql "jasmine-node"
11
+ end
12
+
13
+ it "sets a default :all_after_pass option" do
14
+ guard.options[:all_after_pass].should be_true
15
+ end
16
+
17
+ it "sets a default :all_on_start option" do
18
+ guard.options[:all_on_start].should be_true
19
+ end
20
+
21
+ it "sets a default :keep_failed option" do
22
+ guard.options[:keep_failed].should be_true
23
+ end
24
+
25
+ it "is passing" do
26
+ guard.should be_passing
27
+ end
28
+
29
+ it "has no failing paths" do
30
+ guard.failing_paths.should be_empty
31
+ end
32
+ end
33
+
34
+ context "when options are given" do
35
+ let(:a_path) { "/foo/bar/jasmine-node" }
36
+ let(:guard) { Guard::JasmineNode.new([], {
37
+ :jasmine_node_bin => a_path,
38
+ :all_on_start => false,
39
+ :all_after_pass => false,
40
+ :keep_failed => false
41
+ }) }
42
+
43
+ it "sets the path to jasmine-node bin" do
44
+ guard.options[:jasmine_node_bin].should eql a_path
45
+ end
46
+
47
+ it "sets the :all_after_pass option" do
48
+ guard.options[:all_after_pass].should be_false
49
+ end
50
+
51
+ it "sets the :all_on_start option" do
52
+ guard.options[:all_on_start].should be_false
53
+ end
54
+
55
+ it "sets the :keep_failed option" do
56
+ guard.options[:keep_failed].should be_false
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#start" do
62
+ context "when :all_on_start is true" do
63
+ it "runs all" do
64
+ guard.should_receive(:run_all)
65
+ guard.start
66
+ end
67
+ end
68
+
69
+ context "when :all_on_start is false" do
70
+ let(:guard) { Guard::JasmineNode.new([], { :all_on_start => false }) }
71
+
72
+ it "does not run all" do
73
+ guard.should_not_receive(:run_all)
74
+ guard.start
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "#run_all" do
80
+ it "runs the runner with the spec dir" do
81
+ runner.should_receive(:run).with(["spec"], anything)
82
+ guard.run_all
83
+ end
84
+
85
+ it "tells the message to the runner" do
86
+ runner.should_receive(:run).with(anything, hash_including(:message => "Running all specs"))
87
+ guard.run_all
88
+ end
89
+
90
+ it "passes the options on to the runner" do
91
+ an_option = { :option => "value" }
92
+ guard.options.update(an_option)
93
+ runner.should_receive(:run).with(anything, hash_including(an_option))
94
+ guard.run_all
95
+ end
96
+
97
+ context "when specs pass" do
98
+ before do
99
+ runner.stub(:run => true)
100
+ guard.run_all
101
+ end
102
+
103
+ it "is passing" do
104
+ guard.should be_passing
105
+ end
106
+
107
+ it "has no failed paths" do
108
+ guard.failing_paths.should be_empty
109
+ end
110
+ end
111
+
112
+ context "when specs fail" do
113
+ before do
114
+ runner.stub(:run => false)
115
+ end
116
+
117
+ it "is not passing" do
118
+ guard.run_all
119
+ guard.should_not be_passing
120
+ end
121
+
122
+ it "keeps previously failing specs" do
123
+ failing_paths = %w(foo bar)
124
+ guard.run_on_change(failing_paths)
125
+ guard.run_all
126
+ guard.failing_paths.should eql failing_paths
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "#run_on_change" do
132
+ it "runs the runner with paths" do
133
+ runner.should_receive(:run).with(["/a/path"], anything)
134
+ guard.run_on_change(["/a/path"])
135
+ end
136
+
137
+ it "passes options through to the runner" do
138
+ an_option = { :option => "value" }
139
+ guard.options.update(an_option)
140
+ runner.should_receive(:run).with(anything, hash_including(an_option))
141
+ guard.run_on_change
142
+ end
143
+
144
+ context "when specs pass" do
145
+ before do
146
+ runner.stub(:run => true)
147
+ end
148
+
149
+ it "is passing" do
150
+ guard.run_on_change
151
+ guard.should be_passing
152
+ end
153
+
154
+ context "and :all_after_pass is true" do
155
+ before do
156
+ guard.options[:all_after_pass] = true
157
+ end
158
+
159
+ it "runs all" do
160
+ guard.should_receive(:run_all)
161
+ guard.run_on_change
162
+ end
163
+ end
164
+
165
+ context "and :all_after_pass is false" do
166
+ before do
167
+ guard.options[:all_after_pass] = false
168
+ end
169
+
170
+ context "if :all_after_pass is true" do
171
+ it "does not run all" do
172
+ guard.should_not_receive(:run_all)
173
+ guard.run_on_change
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ context "when specs fail" do
180
+ before do
181
+ runner.stub(:run => false)
182
+ end
183
+
184
+ it "is not passing" do
185
+ guard.run_on_change
186
+ guard.should_not be_passing
187
+ end
188
+ end
189
+
190
+ context "when there are failing paths" do
191
+ let(:failing_paths) { %w(foo/bar zip/zap) }
192
+ let(:changed_paths) { %w(aaa/bbb ccc/ddd) }
193
+ let(:all_paths) { failing_paths + changed_paths }
194
+
195
+ before do
196
+ guard.stub(:failing_paths => failing_paths)
197
+ end
198
+
199
+ context "and :keep_failed is true" do
200
+ before do
201
+ guard.options[:keep_failed] = true
202
+ end
203
+
204
+ it "runs the runner failing paths and the changed paths" do
205
+ runner.should_receive(:run).with(all_paths, anything)
206
+ guard.run_on_change(changed_paths)
207
+ end
208
+ end
209
+
210
+ context "and :keep_failed is false" do
211
+ before do
212
+ guard.options[:keep_failed] = false
213
+ end
214
+
215
+ it "runs the runner with only the changed paths" do
216
+ runner.should_receive(:run).with(changed_paths, anything)
217
+ guard.run_on_change(changed_paths)
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::JasmineNode::Runner do
4
+ let(:runner) { Guard::JasmineNode::Runner }
5
+
6
+ describe ".run" do
7
+ context "when passed no paths" do
8
+ it "returns false" do
9
+ runner.run.should be_false
10
+ end
11
+ end
12
+
13
+ context "when passed paths" do
14
+ let(:some_paths) { %w(/foo/bar /zip/zap) }
15
+
16
+ it "executes jasmine node" do
17
+ runner.should_receive(:system).with(/__EXECUTABLE__/)
18
+ runner.run(some_paths, :jasmine_node_bin => "__EXECUTABLE__")
19
+ end
20
+
21
+ context "when message option is given" do
22
+ it "outputs message" do
23
+ Guard::UI.should_receive(:info).with("hello", anything)
24
+ runner.run(some_paths, :message => "hello")
25
+ end
26
+ end
27
+
28
+ context "when no message option is given" do
29
+ it "outputs default message" do
30
+ Guard::UI.should_receive(:info).with("Running: /foo/bar /zip/zap", anything)
31
+ runner.run(some_paths)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspec'
2
+ require 'guard/jasmine_node'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.filter_run :focus => true
7
+ config.run_all_when_everything_filtered = true
8
+
9
+ config.before do
10
+ ENV["GUARD_ENV"] = "test"
11
+ @project_path = Pathname.new(File.expand_path("../../", __FILE__))
12
+ end
13
+
14
+ config.after do
15
+ ENV["GUARD_ENV"] = nil
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-jasmine-node
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - dave@kapoq.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: &21459700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *21459700
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &21459280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21459280
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-rspec
38
+ requirement: &21458820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21458820
47
+ - !ruby/object:Gem::Dependency
48
+ name: rb-inotify
49
+ requirement: &21458360 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *21458360
58
+ - !ruby/object:Gem::Dependency
59
+ name: libnotify
60
+ requirement: &21457940 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *21457940
69
+ description: ''
70
+ email:
71
+ - dave@kapoq.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - Guardfile
81
+ - README.md
82
+ - Rakefile
83
+ - guard-jasmine-node.gemspec
84
+ - lib/guard/jasmine-node.rb
85
+ - lib/guard/jasmine_node.rb
86
+ - lib/guard/jasmine_node/runner.rb
87
+ - lib/guard/jasmine_node/templates/Guardfile
88
+ - lib/guard/jasmine_node/version.rb
89
+ - spec/spec/jasmine_node_spec.rb
90
+ - spec/spec/runner_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/kapoq/guard-jasmine-node
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project: guard-jasmine-node
112
+ rubygems_version: 1.8.10
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Guard::JasmineNode automatically runs your Jasmine Node specs when files
116
+ are modified
117
+ test_files: []