guard-jasmine-headless-webkit 0.0.5 → 0.1.0

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/Gemfile CHANGED
@@ -2,8 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec
4
4
  gemspec
5
- gem 'guard'
5
+ gem 'guard', :git => 'https://github.com/guard/guard.git'
6
6
  gem 'rspec'
7
7
  gem 'mocha'
8
8
  gem 'rake', '0.8.7'
9
9
  gem 'growl'
10
+ gem 'fakefs', :require => nil
data/README.md CHANGED
@@ -15,9 +15,9 @@ home folder's `.jasmine-headless-webkit` file.
15
15
  ## `guard` options
16
16
 
17
17
  * `:all_on_start => false` to not run everything when starting, just like `guard-rspec`.
18
- * `:run_before => "<command to run>` to run a command before running specs. If the command fails, the test run stops. Useful for running Jammit before running your specs to compile templates:
19
-
20
- `guard 'jasmine-headliness-webkit', :run_before => 'jammit -f 2>/dev/null' do`
18
+ * `:run_before => "<command to run>` to run a command before running specs. If the command fails, the test run stops.
19
+ * `:jammit => true` to run `jammit -f 2>/dev/null` before the tests for the current file change are run.
20
+ * `:valid_extensions => %w{` to run `jammit -f 2>/dev/null` before the tests for the current file change are run.
21
21
 
22
22
  ## What's the deal with `newest_js_file`?
23
23
 
data/Rakefile CHANGED
@@ -6,3 +6,32 @@ task :push_everywhere do
6
6
  system %{git push origin master}
7
7
  system %{git push guard master}
8
8
  end
9
+
10
+ require 'rspec/core/rake_task'
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ namespace :spec do
15
+ desc "Run on three Rubies"
16
+ task :platforms do
17
+ current = %x{rvm-prompt v}
18
+
19
+ fail = false
20
+ %w{1.8.7 1.9.2 ree}.each do |version|
21
+ puts "Switching to #{version}"
22
+ Bundler.with_clean_env do
23
+ system %{bash -c 'source ~/.rvm/scripts/rvm && rvm #{version} && bundle exec rake spec'}
24
+ end
25
+ if $?.exitstatus != 0
26
+ fail = true
27
+ break
28
+ end
29
+ end
30
+
31
+ system %{rvm #{current}}
32
+
33
+ exit (fail ? 1 : 0)
34
+ end
35
+ end
36
+
37
+ task :default => 'spec:platforms'
@@ -4,11 +4,14 @@ require 'guard/jasmine-headless-webkit/runner'
4
4
 
5
5
  module Guard
6
6
  class JasmineHeadlessWebkit < Guard
7
+ DEFAULT_EXTENSIONS = %w{js coffee}
8
+
7
9
  def initialize(watchers = [], options = {})
8
10
  super
9
11
  @options = {
10
12
  :all_on_start => true,
11
- :run_before => false
13
+ :run_before => false,
14
+ :valid_extensions => DEFAULT_EXTENSIONS
12
15
  }.merge(options)
13
16
  end
14
17
 
@@ -18,25 +21,54 @@ module Guard
18
21
  end
19
22
 
20
23
  def run_all
21
- JasmineHeadlessWebkitRunner.run if run_before
24
+ JasmineHeadlessWebkitRunner.run if run_before and run_jammit
25
+ @ran_jammit = false
22
26
  end
23
27
 
24
28
  def run_on_change(paths)
25
- if run_before
26
- run_all if JasmineHeadlessWebkitRunner.run(paths) == 0
29
+ paths = filter_paths(paths)
30
+ @ran_jammit = false
31
+ if run_before and run_jammit
32
+ @ran_jammit = true
33
+ do_run_all = true
34
+ if !paths.empty?
35
+ do_run_all = (JasmineHeadlessWebkitRunner.run(paths) == 0)
36
+ end
37
+ run_all if do_run_all
27
38
  end
28
39
  end
29
40
 
30
41
  private
42
+ def filter_paths(paths)
43
+ paths.find_all { |path| File.extname(path)[valid_extensions] }
44
+ end
45
+
46
+ def valid_extensions
47
+ %r{\.(#{@options[:valid_extensions].join('|')})$}
48
+ end
49
+
31
50
  def run_before
32
51
  if @options[:run_before]
33
- UI.info "Guard::JasmineHeadlessWebkit running #{@options[:run_before]} first..."
34
- system @options[:run_before]
35
- $?.exitstatus == 0
52
+ run_program(@options[:run_before])
53
+ else
54
+ true
55
+ end
56
+ end
57
+
58
+ def run_jammit
59
+ if @options[:jammit] && !@ran_jammit
60
+ run_program("Jammit", %{jammit -f 2>/dev/null})
36
61
  else
37
62
  true
38
63
  end
39
64
  end
65
+
66
+ def run_program(name, command = nil)
67
+ command ||= name
68
+ UI.info "Guard::JasmineHeadlessWebkit running #{name}..."
69
+ system command
70
+ $?.exitstatus == 0
71
+ end
40
72
  end
41
73
 
42
74
  class Dsl
@@ -9,15 +9,25 @@ module Guard
9
9
 
10
10
  system %{jasmine-headless-webkit --report #{file.path} -c #{paths.join(" ")}}
11
11
 
12
- total, fails, any_console, secs = File.read(file.path).strip.split('/')
12
+ notify(file.path)
13
+ end
14
+
15
+ def notify(file)
16
+ if (data = File.read(file).strip).empty?
17
+ Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
18
+ else
19
+ total, fails, any_console, secs = File.read(file).strip.split('/')
13
20
 
14
- Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails))
15
- fails.to_i
21
+ Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails))
22
+ fails.to_i
23
+ end
16
24
  end
17
25
 
18
26
  private
19
27
  def message(total, fails, secs, any_console)
20
- "#{total} tests, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
28
+ total_word = (total.to_i == 1) ? "test" : "tests"
29
+
30
+ "#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
21
31
  end
22
32
 
23
33
  def image(any_console, fails)
@@ -7,9 +7,9 @@ spec_location = "spec/javascripts/%s_spec"
7
7
  # spec_location = "spec/javascripts/%sSpec"
8
8
 
9
9
  guard 'jasmine-headless-webkit' do
10
- watch(%r{^app/views/.*\.jst})
11
- watch(%r{^public/javascripts/(.*)\.js}) { |m| newest_js_file(spec_location % m[1]) }
12
- watch(%r{^app/assets/javascripts/(.*)\.(js|coffee)}) { |m| newest_js_file(spec_location % m[1]) }
10
+ watch(%r{^app/views/.*\.jst$})
11
+ watch(%r{^public/javascripts/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) }
12
+ watch(%r{^app/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
13
13
  watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
14
14
  end
15
15
 
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module JasmineHeadlessWebkitVersion
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'guard/jasmine-headless-webkit/runner'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe Guard::JasmineHeadlessWebkitRunner do
6
+ describe '.notify' do
7
+ include FakeFS::SpecHelpers
8
+
9
+ let(:file) { 'temp.txt' }
10
+
11
+ before do
12
+ File.open(file, 'w') { |fh| fh.print data }
13
+ end
14
+
15
+ context 'system run not interrupted' do
16
+ let(:data) { '1/0/F/5' }
17
+
18
+ it 'should notify with the right information' do
19
+ Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5 secs.", { :title => 'Jasmine results', :image => :success })
20
+
21
+ Guard::JasmineHeadlessWebkitRunner.notify(file)
22
+ end
23
+ end
24
+
25
+ context 'system run interrupted' do
26
+ let(:data) { '' }
27
+
28
+ it 'should notify failure' do
29
+ Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed })
30
+
31
+ Guard::JasmineHeadlessWebkitRunner.notify(file)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -32,7 +32,7 @@ describe Guard::JasmineHeadlessWebkit do
32
32
  Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
33
33
  guard.expects(:run_all).never
34
34
 
35
- guard.run_on_change(%w{test})
35
+ guard.run_on_change(%w{test.js})
36
36
  end
37
37
  end
38
38
 
@@ -41,7 +41,25 @@ describe Guard::JasmineHeadlessWebkit do
41
41
  Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
42
42
  guard.expects(:run_all).once
43
43
 
44
- guard.run_on_change(%w{test})
44
+ guard.run_on_change(%w{test.js})
45
+ end
46
+ end
47
+
48
+ context 'no files given, just run all' do
49
+ it 'should run all but not run once' do
50
+ Guard::JasmineHeadlessWebkitRunner.expects(:run).never
51
+ guard.expects(:run_all).once
52
+
53
+ guard.run_on_change([])
54
+ end
55
+ end
56
+
57
+ context "Files I don't care about given, ignore" do
58
+ it 'should run all but not run once' do
59
+ Guard::JasmineHeadlessWebkitRunner.expects(:run).never
60
+ guard.expects(:run_all).once
61
+
62
+ guard.run_on_change(%w{test.jst})
45
63
  end
46
64
  end
47
65
  end
@@ -50,6 +68,7 @@ describe Guard::JasmineHeadlessWebkit do
50
68
  context 'with failing command' do
51
69
  before do
52
70
  Guard::JasmineHeadlessWebkitRunner.expects(:run).never
71
+ Guard::UI.expects(:info).with(regexp_matches(/false/))
53
72
  end
54
73
 
55
74
  let(:options) { { :run_before => 'false' } }
@@ -62,6 +81,7 @@ describe Guard::JasmineHeadlessWebkit do
62
81
  context 'with succeeding command' do
63
82
  before do
64
83
  Guard::JasmineHeadlessWebkitRunner.expects(:run).once
84
+ Guard::UI.expects(:info).with(regexp_matches(/true/))
65
85
  end
66
86
 
67
87
  let(:options) { { :run_before => 'true' } }
@@ -71,4 +91,32 @@ describe Guard::JasmineHeadlessWebkit do
71
91
  end
72
92
  end
73
93
  end
94
+
95
+ describe 'run jammit first' do
96
+ context 'run on run_all if called first' do
97
+ before do
98
+ guard.expects(:run_program).once.returns(true)
99
+ Guard::JasmineHeadlessWebkitRunner.expects(:run).once
100
+ end
101
+
102
+ let(:options) { { :jammit => true } }
103
+
104
+ it "should run jammit first" do
105
+ guard.run_all
106
+ end
107
+ end
108
+
109
+ context 'only run once if run_on_change is successful' do
110
+ before do
111
+ guard.expects(:run_program).once.returns(true)
112
+ Guard::JasmineHeadlessWebkitRunner.expects(:run).twice.returns(0)
113
+ end
114
+
115
+ let(:options) { { :jammit => true } }
116
+
117
+ it "should run jammit only once" do
118
+ guard.run_on_change(%w{path.js})
119
+ end
120
+ end
121
+ end
74
122
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: guard-jasmine-headless-webkit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bintz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-29 00:00:00 -04:00
13
+ date: 2011-06-07 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - lib/guard/jasmine-headless-webkit/runner.rb
56
56
  - lib/guard/jasmine-headless-webkit/templates/Guardfile
57
57
  - lib/guard/jasmine-headless-webkit/version.rb
58
+ - spec/lib/guard/jasmine-headless-webkit/runner_spec.rb
58
59
  - spec/lib/guard/jasmine-headless-webkit_spec.rb
59
60
  - spec/spec_helper.rb
60
61
  has_rdoc: true
@@ -71,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
- hash: 642568591730735796
75
+ hash: -738405479392593179
75
76
  segments:
76
77
  - 0
77
78
  version: "0"
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements:
81
82
  - - ">="
82
83
  - !ruby/object:Gem::Version
83
- hash: 642568591730735796
84
+ hash: -738405479392593179
84
85
  segments:
85
86
  - 0
86
87
  version: "0"
@@ -92,5 +93,6 @@ signing_key:
92
93
  specification_version: 3
93
94
  summary: Run jasmine-headless-webkit using guard
94
95
  test_files:
96
+ - spec/lib/guard/jasmine-headless-webkit/runner_spec.rb
95
97
  - spec/lib/guard/jasmine-headless-webkit_spec.rb
96
98
  - spec/spec_helper.rb