Compare commits
34 Commits
rails-asse
...
master
Author | SHA1 | Date |
---|---|---|
John Bintz | f86ec8b3b6 | |
Tim Mansfield | f82a1d6059 | |
John Bintz | 644f24cc4c | |
John Bintz | b3e88261f0 | |
John Bintz | 943e754d59 | |
John Bintz | 12b48b1c6d | |
John Bintz | 83e5bd542e | |
John Bintz | b420397349 | |
John Bintz | 6e2be80d6a | |
John Bintz | 7040e0e949 | |
John Bintz | c9e7bb60cb | |
John Bintz | cd27ecb5be | |
Steven Mitcham | 862b82e869 | |
Steven Mitcham | 70b26b2c08 | |
John Bintz | 9b6cb02d06 | |
John Bintz | c2a3635083 | |
John Bintz | 3ed72300d3 | |
John Bintz | 570ea0814e | |
John Bintz | 5baaf8f6e3 | |
John Bintz | cd6004fd3d | |
John Bintz | c467aea42b | |
John Bintz | ce6639f44e | |
John Bintz | 25816daf7f | |
John Bintz | 895ae0c304 | |
John Bintz | 3fb7d8ac24 | |
John Bintz | 245eeba260 | |
John Bintz | 7ca6900570 | |
John Bintz | 56e71e7ada | |
John Bintz | 8b65ee4ed3 | |
John Bintz | 93a8d546b8 | |
John Bintz | 74d4ce577f | |
John Bintz | e776f24970 | |
John Bintz | 9f27c50156 | |
John Bintz | e1a01fb44e |
|
@ -2,3 +2,5 @@
|
|||
.bundle
|
||||
Gemfile.lock
|
||||
pkg/*
|
||||
*.orig
|
||||
|
||||
|
|
15
Gemfile
15
Gemfile
|
@ -2,10 +2,19 @@ source "http://rubygems.org"
|
|||
|
||||
# Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec
|
||||
gemspec
|
||||
gem 'guard', :git => 'https://github.com/guard/guard.git'
|
||||
gem 'rake', '0.9.2'
|
||||
|
||||
gem 'rspec'
|
||||
gem 'cucumber'
|
||||
gem 'mocha'
|
||||
gem 'rake', '0.8.7'
|
||||
gem 'growl'
|
||||
gem 'fakefs', :require => nil
|
||||
|
||||
gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit'
|
||||
|
||||
gem 'guard', :git => 'git://github.com/guard/guard.git'
|
||||
gem 'guard-rspec'
|
||||
gem 'guard-cucumber'
|
||||
|
||||
gem 'growl'
|
||||
gem 'rb-fsevent'
|
||||
|
||||
|
|
16
Guardfile
16
Guardfile
|
@ -5,13 +5,11 @@ guard 'rspec', :cli => '-c', :version => 2 do
|
|||
watch(%r{^spec/.+_spec\.rb})
|
||||
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
||||
# Rails example
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
watch('config/routes.rb') { "spec/routing" }
|
||||
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
||||
watch(%r{^spec/.+_spec\.rb})
|
||||
watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
||||
end
|
||||
|
||||
guard 'cucumber', :cli => '-f pretty' do
|
||||
watch(%r{^features/.+\.feature$})
|
||||
watch(%r{^features/support/.+$}) { 'features' }
|
||||
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2011 John Bintz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
43
README.md
43
README.md
|
@ -2,9 +2,11 @@
|
|||
|
||||
Add running your Jasmine specs to your `Guardfile` via [`jasmine-headless-webkit`](http://github.com/johnbintz/jasmine-headless-webkit/). Nice!
|
||||
|
||||
guard 'jasmine-headless-webkit' do
|
||||
``` ruby
|
||||
guard 'jasmine-headless-webkit' do
|
||||
watch(%r{^app/assets/javascripts/(.*)\..*}) { |m| newest_js_file("spec/javascripts/#{m[1]}_spec") }
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
`gem install guard-jasmine-headless-webkit` and then `guard init jasmine-headless-webkit` in your project directory to get started.
|
||||
You should also put it in your `Gemfile` because, hey, why not, right?
|
||||
|
@ -15,14 +17,31 @@ home folder's `.jasmine-headless-webkit` file.
|
|||
## `guard` options
|
||||
|
||||
* `:all_on_start => false` to not run everything when starting, just like `guard-rspec`.
|
||||
* `:rails_assets => true` to repackage Rails assets before each run.
|
||||
* `:run_before => "<command to run>"` to run a command before running specs. If the command fails, the test run stops.
|
||||
* `:valid_extensions => %w{js coffee}` to only trigger `run_on_change` events for files with these extensions. Forces Guard to re-run all tests when any other matched file changes.
|
||||
* All other options from `Jasmine::Headless::Runner`: (see the [list of available options](https://github.com/johnbintz/jasmine-headless-webkit/blob/master/lib/jasmine/headless/options.rb#L11A))
|
||||
|
||||
### Deprecated options
|
||||
## Using with .erb files in the Rails 3.1 Asset Pipeline and/or Jammit
|
||||
|
||||
* `:jammit => true` to run `jammit -f 2>/dev/null` before the tests for the current file change are run.
|
||||
* Use [guard-jammit](http://github.com/guard/guard-jammit) instead.
|
||||
If your code required Jammit or ERB templates, which aren't directly supported by `jasmine-headledd-webkit`,
|
||||
use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application
|
||||
code for testing:
|
||||
|
||||
``` ruby
|
||||
guard 'rails-assets' do
|
||||
watch(%r{^app/assets/javascripts/.*})
|
||||
end
|
||||
|
||||
guard 'jasmine-headless-webkit' do
|
||||
watch(%r{^public/assets/.*\.js})
|
||||
... specs ...
|
||||
end
|
||||
```
|
||||
|
||||
Do the same for Jammit, using [`guard-jammit`](http://github.com/guard/guard-jammit).
|
||||
|
||||
### `guard-jammit` and Jammit >= 0.6.0
|
||||
|
||||
Jammit >= 0.6.0 changed how it determines the Rails environment. Use [my fork of `guard-jammit`](http://github.com/johnbintz/guard-jammit) until it's fixed upstream.
|
||||
|
||||
## What's the deal with `newest_js_file`?
|
||||
|
||||
|
@ -34,12 +53,8 @@ file is a little more complicated. `newest_js_file` extends the Guard DSL to sea
|
|||
|
||||
If you 100% know you won't need that support, modify your `Guardfile` as appropriate.
|
||||
|
||||
## ...and the `.jst` file search?
|
||||
## License
|
||||
|
||||
I use [Backbone.js](http://documentcloud.github.com/backbone/) a lot, and I put my Underscore view templates in `app/views/*.jst`
|
||||
and mash them all together with [Jammit](https://github.com/documentcloud/jammit) for use in my apps. Feel free to change that, it's your `Guardfile` after all.
|
||||
Or, try it. It's easy to do in your `assets.yml` file:
|
||||
|
||||
templates:
|
||||
- app/views/*.jst
|
||||
This library is released under the MIT license:
|
||||
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
|
|
35
Rakefile
35
Rakefile
|
@ -1,6 +1,8 @@
|
|||
require 'bundler'
|
||||
Bundler::GemHelper.install_tasks
|
||||
|
||||
include Rake::DSL if defined?(Rake::DSL)
|
||||
|
||||
desc 'Push everywhere!'
|
||||
task :push_everywhere do
|
||||
system %{git push origin master}
|
||||
|
@ -11,27 +13,26 @@ require 'rspec/core/rake_task'
|
|||
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3}
|
||||
|
||||
def rvm_bundle(command = '')
|
||||
Bundler.with_clean_env do
|
||||
system %{bash -c 'unset BUNDLE_BIN_PATH && unset BUNDLE_GEMFILE && rvm #{PLATFORMS.join(',')} do bundle #{command}'}
|
||||
end
|
||||
end
|
||||
|
||||
class SpecFailure < StandardError; end
|
||||
class BundleFailure < StandardError; end
|
||||
|
||||
namespace :spec do
|
||||
desc "Run on three Rubies"
|
||||
task :platforms do
|
||||
current = %x{rvm-prompt v}
|
||||
|
||||
fail = false
|
||||
%w{1.8.7 1.9.2 ree}.each do |version|
|
||||
puts "Switching to #{version}"
|
||||
Bundler.with_clean_env do
|
||||
system %{bash -c 'source ~/.rvm/scripts/rvm && rvm #{version} && bundle exec rake spec'}
|
||||
end
|
||||
if $?.exitstatus != 0
|
||||
fail = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
system %{rvm #{current}}
|
||||
|
||||
exit (fail ? 1 : 0)
|
||||
rvm_bundle "update"
|
||||
rvm_bundle "exec rspec spec"
|
||||
rvm_bundle "exec cucumber"
|
||||
raise SpecError.new if $?.exitstatus != 0
|
||||
end
|
||||
end
|
||||
|
||||
task :default => 'spec:platforms'
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
Feature: Runner
|
||||
Scenario: Don't specify a reporter
|
||||
Given I am going to call a JHW runner with the following reporters:
|
||||
| name | file |
|
||||
| Console | |
|
||||
| File | notify-file |
|
||||
And I am going to get a notification file
|
||||
When I don't specify a reporter
|
||||
And I run the runner
|
||||
Then I should get the reporters
|
||||
|
||||
Scenario: Specify another console reporter
|
||||
Given I am going to call a JHW runner with the following reporters:
|
||||
| name | file |
|
||||
| Verbose | |
|
||||
| File | notify-file |
|
||||
And I am going to get a notification file
|
||||
When I specify the reporter "Verbose"
|
||||
And I run the runner
|
||||
Then I should get the reporters
|
||||
And the reporter string should not have changed
|
||||
|
||||
Scenario: Specify two reporters
|
||||
Given I am going to call a JHW runner with the following reporters:
|
||||
| name | file |
|
||||
| Verbose | |
|
||||
| Tap | tap-file |
|
||||
| File | notify-file |
|
||||
And I am going to get a notification file
|
||||
When I specify the reporter "Verbose Tap:tap-file"
|
||||
And I run the runner
|
||||
Then I should get the reporters
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Given /^I am going to call a JHW runner with the following reporters:$/ do |table|
|
||||
reporters = []
|
||||
|
||||
table.rows.each do | name, file |
|
||||
reporters << [ name ]
|
||||
|
||||
reporters.last << file if !file.empty?
|
||||
end
|
||||
|
||||
Jasmine::Headless::Runner.expects(:run).with(has_entry(:reporters => reporters))
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:notify)
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Given /^I am going to get a notification file$/ do
|
||||
Guard::JasmineHeadlessWebkit::Runner.stubs(:notify_report_file).returns(@report_file)
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
Then /^I should get the reporters$/ do
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Then /^the reporter string should not have changed$/ do
|
||||
@options[:reporters].should == @requested_reporter
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
When /^I don't specify a reporter$/ do
|
||||
@options = {}
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
When /^I run the runner$/ do
|
||||
Guard::JasmineHeadlessWebkit::Runner.run(@paths, @options)
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
When /^I specify the reporter "([^"]*)"$/ do |reporter|
|
||||
@requested_reporter = reporter
|
||||
|
||||
@options = { :reporters => reporter }
|
||||
end
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
require 'rspec'
|
||||
require 'mocha'
|
||||
require 'fakefs/safe'
|
||||
|
||||
require 'jasmine-headless-webkit'
|
||||
require 'guard/jasmine-headless-webkit'
|
||||
|
||||
require 'coffee-script'
|
||||
|
||||
World(Mocha::API)
|
||||
|
||||
Before do
|
||||
mocha_setup
|
||||
|
||||
FakeFS.activate!
|
||||
|
||||
@report_file = 'notify-file'
|
||||
@paths = []
|
||||
end
|
||||
|
||||
After do
|
||||
begin
|
||||
mocha_verify
|
||||
ensure
|
||||
mocha_teardown
|
||||
end
|
||||
|
||||
FakeFS.deactivate!
|
||||
end
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
require "guard/jasmine-headless-webkit/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "guard-jasmine-headless-webkit"
|
||||
s.version = Guard::JasmineHeadlessWebkitVersion::VERSION
|
||||
s.version = '0.4.0.rc1'
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["John Bintz"]
|
||||
s.email = ["john@coswellproductions.com"]
|
||||
|
@ -19,6 +17,7 @@ Gem::Specification.new do |s|
|
|||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.add_dependency 'guard', '>= 0.4.0'
|
||||
s.add_dependency 'jasmine-headless-webkit', '>= 0.3.0'
|
||||
s.add_runtime_dependency 'guard', '>= 0.4.0'
|
||||
s.add_runtime_dependency 'jasmine-headless-webkit', '>= 0.7.0'
|
||||
end
|
||||
|
||||
|
|
|
@ -1,18 +1,32 @@
|
|||
require 'guard'
|
||||
require 'guard/guard'
|
||||
require 'guard/jasmine-headless-webkit/runner'
|
||||
require 'coffee-script'
|
||||
|
||||
module Guard
|
||||
class JasmineHeadlessWebkit < Guard
|
||||
autoload :Runner, 'guard/jasmine-headless-webkit/runner'
|
||||
|
||||
DEFAULT_EXTENSIONS = %w{js coffee}
|
||||
|
||||
def initialize(watchers = [], options = {})
|
||||
super
|
||||
@options = {
|
||||
ALL_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running all specs..."
|
||||
SOME_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running the following: %s"
|
||||
|
||||
attr_reader :files_to_rerun
|
||||
|
||||
DEFAULT_OPTIONS = {
|
||||
:all_on_start => true,
|
||||
:run_before => false,
|
||||
:valid_extensions => DEFAULT_EXTENSIONS
|
||||
}.merge(options)
|
||||
}
|
||||
|
||||
def initialize(watchers = [], options = {})
|
||||
super
|
||||
|
||||
@options = DEFAULT_OPTIONS.merge(options)
|
||||
@filtered_options = options
|
||||
DEFAULT_OPTIONS.keys.each { |key| @filtered_options.delete(key) }
|
||||
|
||||
@files_to_rerun = []
|
||||
end
|
||||
|
||||
def start
|
||||
|
@ -20,20 +34,23 @@ module Guard
|
|||
run_all if @options[:all_on_start]
|
||||
end
|
||||
|
||||
def reload
|
||||
@files_to_rerun = []
|
||||
UI.info "Resetting Guard::JasmineHeadlessWebkit failed files..."
|
||||
end
|
||||
|
||||
def run_all
|
||||
UI.info "Guard::JasmineHeadlessWebkit running all specs..."
|
||||
JasmineHeadlessWebkitRunner.run if run_all_things_before
|
||||
@ran_before = false
|
||||
run_something_and_rescue do
|
||||
run_for_failed_files
|
||||
end
|
||||
end
|
||||
|
||||
def run_on_change(paths)
|
||||
paths = filter_paths(paths)
|
||||
@ran_before = false
|
||||
if run_all_things_before
|
||||
@ran_before = true
|
||||
if !paths.empty?
|
||||
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
|
||||
JasmineHeadlessWebkitRunner.run(paths)
|
||||
run_something_and_rescue do
|
||||
if !(paths = filter_paths(paths)).empty?
|
||||
paths = (paths + @files_to_rerun).uniq
|
||||
|
||||
run_for_failed_files(paths)
|
||||
else
|
||||
run_all
|
||||
end
|
||||
|
@ -41,45 +58,45 @@ module Guard
|
|||
end
|
||||
|
||||
private
|
||||
def run_for_failed_files(paths = [])
|
||||
if paths.empty?
|
||||
UI.info(ALL_SPECS_MESSAGE)
|
||||
else
|
||||
UI.info(SOME_SPECS_MESSAGE % paths.join(' '))
|
||||
end
|
||||
failed_files = Runner.run(paths, @filtered_options)
|
||||
@files_to_rerun = failed_files || paths
|
||||
|
||||
failed_files && @files_to_rerun.empty?
|
||||
end
|
||||
|
||||
def filter_paths(paths)
|
||||
paths.find_all { |path| File.extname(path)[valid_extensions] }
|
||||
paths.collect { |path| Dir[path] }.flatten.find_all { |path| File.extname(path)[valid_extensions] }.collect { |path| File.expand_path(path) }.uniq
|
||||
end
|
||||
|
||||
def valid_extensions
|
||||
%r{\.(#{@options[:valid_extensions].join('|')})$}
|
||||
end
|
||||
|
||||
def run_before
|
||||
run_a_thing_before(:run_before, @options[:run_before])
|
||||
end
|
||||
|
||||
def run_jammit
|
||||
$stderr.puts "Jammit support is deprecated and will be removed in the future. Use guard-jammit instead." if @options[:jammit]
|
||||
run_a_thing_before(:jammit, "Jammit", %{jammit -f 2>/dev/null})
|
||||
end
|
||||
|
||||
def run_rails_assets
|
||||
run_a_thing_before(:rails_assets, "Rails Assets", %{rake assets:precompile:for_testing})
|
||||
end
|
||||
|
||||
def run_a_thing_before(option, *args)
|
||||
if @options[option] && !@ran_before
|
||||
run_program(*args)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def run_all_things_before
|
||||
run_before and run_rails_assets and run_jammit
|
||||
end
|
||||
|
||||
def run_program(name, command = nil)
|
||||
command ||= name
|
||||
UI.info "Guard::JasmineHeadlessWebkit running #{name}..."
|
||||
system command
|
||||
$?.exitstatus == 0
|
||||
end
|
||||
|
||||
def run_something_and_rescue
|
||||
yield
|
||||
rescue ::CoffeeScript::CompilationError
|
||||
rescue StandardError => e
|
||||
if ENV['GUARD_ENV'] == 'test'
|
||||
raise e
|
||||
else
|
||||
puts e.message
|
||||
puts e.backtrace.join("\n")
|
||||
puts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Dsl
|
||||
|
|
|
@ -1,37 +1,60 @@
|
|||
require 'guard/notifier'
|
||||
require 'jasmine/headless/runner'
|
||||
require 'jasmine-headless-webkit'
|
||||
|
||||
module Guard
|
||||
class JasmineHeadlessWebkitRunner
|
||||
class << self
|
||||
def run(paths = [])
|
||||
class JasmineHeadlessWebkit
|
||||
class Runner
|
||||
def self.run(paths = [], options = {})
|
||||
report_file = notify_report_file
|
||||
|
||||
options = options.merge(:reporters => process_reporters(options[:reporters], report_file), :colors => true, :files => paths)
|
||||
|
||||
Jasmine::Headless::Runner.run(options)
|
||||
|
||||
notify(report_file)
|
||||
end
|
||||
|
||||
def self.notify_report_file
|
||||
file = Tempfile.new('guard-jasmine-headless-webkit')
|
||||
file.close
|
||||
|
||||
Jasmine::Headless::Runner.run(:report => file.path, :colors => true, :files => paths)
|
||||
|
||||
notify(file.path)
|
||||
file.path
|
||||
end
|
||||
|
||||
def notify(file)
|
||||
if (data = File.read(file).strip).empty?
|
||||
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
|
||||
def self.process_reporters(reporters, report_file)
|
||||
reporters ||= 'Console'
|
||||
|
||||
out = []
|
||||
|
||||
reporters.split(' ').each do |reporter|
|
||||
name, file = reporter.split(':', 2)
|
||||
|
||||
out << [ name ]
|
||||
out.last << file if file && !file.empty?
|
||||
end
|
||||
|
||||
out + [ [ 'File', report_file ] ]
|
||||
end
|
||||
|
||||
def self.notify(file)
|
||||
if (report = Jasmine::Headless::Report.load(file)).valid?
|
||||
Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed))
|
||||
report.failed_files
|
||||
else
|
||||
total, fails, any_console, secs = File.read(file).strip.split('/')
|
||||
|
||||
Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails))
|
||||
fails.to_i
|
||||
raise Jasmine::Headless::InvalidReport
|
||||
end
|
||||
rescue Jasmine::Headless::InvalidReport => e
|
||||
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
def message(total, fails, secs, any_console)
|
||||
def self.message(total, fails, secs, any_console)
|
||||
total_word = (total.to_i == 1) ? "test" : "tests"
|
||||
|
||||
"#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
|
||||
end
|
||||
|
||||
def image(any_console, fails)
|
||||
def self.image(any_console, fails)
|
||||
if any_console
|
||||
:pending
|
||||
else
|
||||
|
@ -45,4 +68,3 @@ module Guard
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Run JS and CoffeeScript files in a typical Rails 3.1 fashion, placing Underscore templates in app/views/*.jst
|
||||
# Run JS and CoffeeScript files in a typical Rails 3.1/Sprockets fashion.
|
||||
# Your spec files end with _spec.{js,coffee}.
|
||||
|
||||
spec_location = "spec/javascripts/%s_spec"
|
||||
|
@ -7,9 +7,7 @@ spec_location = "spec/javascripts/%s_spec"
|
|||
# spec_location = "spec/javascripts/%sSpec"
|
||||
|
||||
guard 'jasmine-headless-webkit' do
|
||||
watch(%r{^app/views/.*\.jst$})
|
||||
watch(%r{^public/javascripts/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) }
|
||||
watch(%r{^app/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
|
||||
watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
|
||||
watch(%r{^(app|lib|vendor)/assets/javascripts/(.*)$}) { |m| newest_js_file(spec_location % m[1]) }
|
||||
watch(%r{^spec/javascripts/(.*)[Ss]pec\..*}) { |m| newest_js_file(spec_location % m[1]) }
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
module Guard
|
||||
module JasmineHeadlessWebkitVersion
|
||||
VERSION = "0.1.1"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'penchant'
|
||||
|
||||
if Penchant::Gemfile.do_full_env_switch!(ARGV[0])
|
||||
puts "Gemfile switched to #{ARGV[0]}"
|
||||
else
|
||||
exit 0
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
OLD_GIT_DIR=$GIT_DIR
|
||||
|
||||
if [ "$(penchant gemfile-env)" != "remote" ]; then
|
||||
unset GIT_DIR
|
||||
penchant gemfile remote
|
||||
GIT_DIR=$OLD_GIT_DIR
|
||||
git add Gemfile*
|
||||
fi
|
||||
|
||||
bundle exec rake
|
||||
R=$?
|
||||
if [ $R -ne 0 ]; then exit $R; fi
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
if File.file?('Gemfile.erb')
|
||||
pwd = Dir.pwd
|
||||
|
||||
Dir.chdir '..' do
|
||||
File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
|
||||
repo = line[%r{:git => (['"])(.*)\1}, 2]
|
||||
|
||||
puts "Installing #{repo}"
|
||||
system %{git clone #{repo}}
|
||||
end
|
||||
end
|
||||
|
||||
puts "Bundling for local environment"
|
||||
system %{script/gemfile local}
|
||||
else
|
||||
puts "Bundling..."
|
||||
system %{bundle}
|
||||
end
|
||||
|
||||
puts "Installing git hooks"
|
||||
system %{script/install-git-hooks}
|
||||
|
||||
bundle = File.file?('Gemfile') ? 'bundle exec' : ''
|
||||
|
||||
command = [ bundle, 'rake', '-s', '-T', 'bootstrap' ]
|
||||
|
||||
if !(%x{#{command.join(' ')}}).empty?
|
||||
puts "Trying to run rake bootstrap..."
|
||||
system %{#{bundle} rake bootstrap}
|
||||
end
|
||||
|
||||
puts "Done!"
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
for hook in script/hooks/* ; do
|
||||
ln -sf $PWD/$hook .git/hooks/${hook##*/}
|
||||
done
|
||||
|
|
@ -1,8 +1,44 @@
|
|||
require 'spec_helper'
|
||||
require 'guard/jasmine-headless-webkit/runner'
|
||||
require 'fakefs/spec_helpers'
|
||||
|
||||
describe Guard::JasmineHeadlessWebkitRunner do
|
||||
describe Guard::JasmineHeadlessWebkit::Runner do
|
||||
describe '.run' do
|
||||
let(:reporter) { 'reporter' }
|
||||
|
||||
before do
|
||||
described_class.stubs(:process_reporters).returns([ reporter ])
|
||||
end
|
||||
|
||||
it 'should pass along options' do
|
||||
Jasmine::Headless::Runner.expects(:run).with(all_of(has_key(:full_run), has_entry(:reporters => [ reporter ])))
|
||||
|
||||
Guard::JasmineHeadlessWebkit::Runner.run([], :full_run => false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.process_reporters' do
|
||||
subject { described_class.process_reporters(reporters, report_file) }
|
||||
|
||||
let(:report_file) { 'report file' }
|
||||
|
||||
context 'none provided' do
|
||||
let(:reporters) { nil }
|
||||
|
||||
it { should == [ [ 'Console' ], [ 'File', report_file ] ] }
|
||||
end
|
||||
|
||||
context 'one provided' do
|
||||
let(:reporters) { 'One' }
|
||||
|
||||
it { should == [ [ 'One' ], [ 'File', report_file ] ] }
|
||||
end
|
||||
|
||||
context 'two provided' do
|
||||
let(:reporters) { 'One Two:file.txt' }
|
||||
|
||||
it { should == [ [ 'One' ], [ 'Two', 'file.txt' ], [ 'File', report_file ] ] }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.notify' do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
|
@ -13,12 +49,25 @@ describe Guard::JasmineHeadlessWebkitRunner do
|
|||
end
|
||||
|
||||
context 'system run not interrupted' do
|
||||
let(:data) { '1/0/F/5' }
|
||||
let(:data) { 'TOTAL||1||0||5||F' }
|
||||
|
||||
it 'should notify with the right information' do
|
||||
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5 secs.", { :title => 'Jasmine results', :image => :success })
|
||||
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :success })
|
||||
|
||||
Guard::JasmineHeadlessWebkitRunner.notify(file)
|
||||
Guard::JasmineHeadlessWebkit::Runner.notify(file).should == []
|
||||
end
|
||||
end
|
||||
|
||||
context 'with failures' do
|
||||
let(:data) { <<-REPORT }
|
||||
FAIL||Test||Two||file.js:50
|
||||
TOTAL||1||1||5||F
|
||||
REPORT
|
||||
|
||||
it 'should notify with the right information' do
|
||||
Guard::Notifier.expects(:notify).with("1 test, 1 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :failed })
|
||||
|
||||
Guard::JasmineHeadlessWebkit::Runner.notify(file).should == [ 'file.js' ]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,7 +77,7 @@ describe Guard::JasmineHeadlessWebkitRunner do
|
|||
it 'should notify failure' do
|
||||
Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed })
|
||||
|
||||
Guard::JasmineHeadlessWebkitRunner.notify(file)
|
||||
Guard::JasmineHeadlessWebkit::Runner.notify(file).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require 'spec_helper'
|
||||
require 'guard/jasmine-headless-webkit'
|
||||
|
||||
describe Guard::JasmineHeadlessWebkit do
|
||||
let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) }
|
||||
|
@ -26,127 +25,158 @@ describe Guard::JasmineHeadlessWebkit do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#run_on_change' do
|
||||
context 'jhw call fails' do
|
||||
it "should not run all" do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
|
||||
guard.expects(:run_all).never
|
||||
describe '#run_all' do
|
||||
before do
|
||||
guard.stubs(:run_all_things_before).returns(true)
|
||||
end
|
||||
|
||||
guard.run_on_change(%w{test.js})
|
||||
context 'fails' do
|
||||
it 'should return false' do
|
||||
Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns(['file.js'])
|
||||
|
||||
guard.run_all.should be_false
|
||||
guard.files_to_rerun.should == ['file.js']
|
||||
end
|
||||
end
|
||||
|
||||
context 'succeeds' do
|
||||
it 'should return true' do
|
||||
Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns([])
|
||||
|
||||
guard.run_all.should be_true
|
||||
guard.files_to_rerun.should == []
|
||||
end
|
||||
end
|
||||
|
||||
context 'pass along jhw options' do
|
||||
let(:options) { { :all_on_start => false, :full_run => false } }
|
||||
|
||||
it 'should only pass along jhw options' do
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with([], :full_run => false)
|
||||
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#run_on_change' do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:one_file) { %w{test.js} }
|
||||
|
||||
def absolute(file)
|
||||
case file
|
||||
when Array
|
||||
file.collect { |f| absolute(f) }
|
||||
else
|
||||
File.expand_path(file)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
File.open(one_file.first, 'wb')
|
||||
end
|
||||
|
||||
context 'two files' do
|
||||
it "should only run one" do
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file), {}).returns(one_file)
|
||||
|
||||
guard.run_on_change(%w{test.js test.js}).should be_false
|
||||
guard.files_to_rerun.should == one_file
|
||||
end
|
||||
end
|
||||
|
||||
context 'one file no priors' do
|
||||
it "should not run all" do
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns(one_file)
|
||||
|
||||
guard.run_on_change(one_file).should be_false
|
||||
guard.files_to_rerun.should == one_file
|
||||
end
|
||||
end
|
||||
|
||||
context 'one file one prior' do
|
||||
it "should not run all" do
|
||||
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file) + [ "two.js" ], {}).returns(one_file)
|
||||
|
||||
guard.run_on_change(one_file).should be_false
|
||||
guard.files_to_rerun.should == one_file
|
||||
end
|
||||
end
|
||||
|
||||
context 'failed hard' do
|
||||
it "should not run all" do
|
||||
guard.instance_variable_set(:@files_to_rerun, absolute(one_file))
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file), {}).returns(false)
|
||||
|
||||
guard.run_on_change(one_file).should be_false
|
||||
guard.files_to_rerun.should == absolute(one_file)
|
||||
end
|
||||
end
|
||||
|
||||
context 'succeed, but still do not run all' do
|
||||
it "should run all" do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
|
||||
guard.expects(:run_all).never
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns([])
|
||||
|
||||
guard.run_on_change(%w{test.js})
|
||||
guard.run_on_change(one_file).should be_true
|
||||
guard.files_to_rerun.should == []
|
||||
end
|
||||
end
|
||||
|
||||
context 'no files given, just run all' do
|
||||
it 'should run all but not run once' do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||
guard.expects(:run_all).once
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).never
|
||||
guard.expects(:run_all).once.returns(true)
|
||||
|
||||
guard.run_on_change([])
|
||||
guard.run_on_change([]).should be_true
|
||||
guard.files_to_rerun.should == []
|
||||
end
|
||||
end
|
||||
|
||||
context "Files I don't care about given, ignore" do
|
||||
it 'should run all but not run once' do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).never
|
||||
guard.expects(:run_all).once
|
||||
|
||||
guard.run_on_change(%w{test.jst})
|
||||
end
|
||||
guard.files_to_rerun.should == []
|
||||
end
|
||||
end
|
||||
|
||||
context 'with run_before' do
|
||||
context 'with failing command' do
|
||||
context 'glob given' do
|
||||
let(:files) { %w{file1.js file2.js other.js} }
|
||||
|
||||
before do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||
Guard::UI.expects(:info).with(regexp_matches(/false/))
|
||||
Guard::UI.expects(:info).with(regexp_matches(/running all/))
|
||||
files.each { |file| File.open(file, 'wb') }
|
||||
end
|
||||
|
||||
let(:options) { { :run_before => 'false' } }
|
||||
context 'not a duplicate' do
|
||||
it 'should expand the glob' do
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false)
|
||||
|
||||
it "should run the command first" do
|
||||
guard.run_all
|
||||
guard.run_on_change(%w{file*.js})
|
||||
end
|
||||
end
|
||||
|
||||
context 'with succeeding command' do
|
||||
before do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
|
||||
Guard::UI.expects(:info).with(regexp_matches(/true/))
|
||||
Guard::UI.expects(:info).with(regexp_matches(/running all/))
|
||||
context 'a duplicate' do
|
||||
it 'should expand the glob and uniq' do
|
||||
guard.instance_variable_set(:@files_to_rerun, absolute(%w{file1.js}))
|
||||
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false)
|
||||
|
||||
guard.run_on_change(%w{file*.js})
|
||||
end
|
||||
|
||||
let(:options) { { :run_before => 'true' } }
|
||||
|
||||
it "should run the command first" do
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'run jammit first' do
|
||||
context 'run on run_all if called first' do
|
||||
before do
|
||||
guard.expects(:run_program).once.with('Jammit', regexp_matches(/jammit/)).returns(true)
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
|
||||
end
|
||||
describe '#reload' do
|
||||
it 'should reset the state of the files_to_rerun' do
|
||||
Guard::UI.expects(:info).with(regexp_matches(/Resetting/))
|
||||
|
||||
let(:options) { { :jammit => true } }
|
||||
|
||||
it "should run jammit first" do
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
|
||||
context 'only run once if run_on_change is successful' do
|
||||
before do
|
||||
guard.expects(:run_program).once.with('Jammit', regexp_matches(/jammit/)).returns(true)
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0)
|
||||
end
|
||||
|
||||
let(:options) { { :jammit => true } }
|
||||
|
||||
it "should run jammit only once" do
|
||||
guard.run_on_change(%w{path.js})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'run rails_assets first' do
|
||||
context 'run on run_all if called first' do
|
||||
before do
|
||||
guard.expects(:run_program).with('Rails Assets', regexp_matches(/assets:precompile:for_testing/)).once.returns(true)
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
|
||||
end
|
||||
|
||||
let(:options) { { :rails_assets => true } }
|
||||
|
||||
it "should run rails assets first" do
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
|
||||
context 'only run once if run_on_change is successful' do
|
||||
before do
|
||||
guard.expects(:run_program).with('Rails Assets', regexp_matches(/assets:precompile:for_testing/)).once.returns(true)
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0)
|
||||
end
|
||||
|
||||
let(:options) { { :rails_assets => true } }
|
||||
|
||||
it "should run rails assets only once" do
|
||||
guard.run_on_change(%w{path.js})
|
||||
end
|
||||
guard.instance_variable_set(:@files_to_rerun, "test")
|
||||
guard.reload
|
||||
guard.files_to_rerun.should == []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
require 'mocha'
|
||||
require 'guard'
|
||||
require 'guard/jasmine-headless-webkit'
|
||||
require 'fakefs/spec_helpers'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
|
||||
ENV['GUARD_ENV'] = 'test'
|
||||
|
||||
module Guard
|
||||
module UI
|
||||
class << self
|
||||
|
|
Loading…
Reference in New Issue