yeehaw!
This commit is contained in:
commit
45b1c44e5b
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
*.gem
|
||||
*.rbc
|
||||
.bundle
|
||||
.config
|
||||
.yardoc
|
||||
Gemfile.lock
|
||||
InstalledFiles
|
||||
_yardoc
|
||||
coverage
|
||||
doc/
|
||||
lib/bundler/man
|
||||
pkg
|
||||
rdoc
|
||||
spec/reports
|
||||
test/tmp
|
||||
test/version_tmp
|
||||
tmp
|
7
Gemfile
Normal file
7
Gemfile
Normal file
@ -0,0 +1,7 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
# Specify your gem's dependencies in flowerbox.gemspec
|
||||
gemspec
|
||||
|
||||
gem 'flowerbox-delivery', :path => '../flowerbox-delivery'
|
||||
|
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
Copyright (c) 2012 John Bintz
|
||||
|
||||
MIT License
|
||||
|
||||
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.
|
29
README.md
Normal file
29
README.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Flowerbox
|
||||
|
||||
TODO: Write a gem description
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
gem 'flowerbox'
|
||||
|
||||
And then execute:
|
||||
|
||||
$ bundle
|
||||
|
||||
Or install it yourself as:
|
||||
|
||||
$ gem install flowerbox
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Write usage instructions here
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Added some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create new Pull Request
|
44
bin/flowerbox
Executable file
44
bin/flowerbox
Executable file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'flowerbox'
|
||||
require 'flowerbox-delivery'
|
||||
require 'thor'
|
||||
|
||||
class Flowerbox::CLI < Thor
|
||||
desc "test DIR SPEC_PATTERN", "Run the specs found in spec dir"
|
||||
method_options :pwd => :string
|
||||
def test(dir)
|
||||
Dir.chdir(pwd) do
|
||||
load File.join(dir, 'spec_helper.rb')
|
||||
|
||||
require 'tilt/coffee'
|
||||
|
||||
Tilt::CoffeeScriptTemplate.default_bare = Flowerbox.bare_coffeescript
|
||||
|
||||
sprockets = Flowerbox::Delivery::SprocketsHandler.new(:asset_paths => [ dir, Flowerbox.asset_paths ].flatten)
|
||||
|
||||
Flowerbox.load_test_environment(sprockets)
|
||||
|
||||
Flowerbox.spec_patterns.each do |pattern|
|
||||
Dir[File.join(dir, pattern)].each do |file|
|
||||
|
||||
sprockets.add(file.gsub(dir + '/', ''))
|
||||
end
|
||||
end
|
||||
|
||||
exit Flowerbox::Runner::Node.run(sprockets.files)
|
||||
end
|
||||
end
|
||||
|
||||
no_tasks do
|
||||
def pwd
|
||||
options[:pwd] || Dir.pwd
|
||||
end
|
||||
|
||||
def asset_paths
|
||||
Flowerbox.asset_paths.collect { |path| File.join(pwd, path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Flowerbox::CLI.start
|
30
features/basic_run.feature
Normal file
30
features/basic_run.feature
Normal file
@ -0,0 +1,30 @@
|
||||
Feature: Basic Run
|
||||
Scenario: Use the Node runner using Jasmine
|
||||
Given I have the file "spec/javascripts/spec_helper.rb" with the content:
|
||||
"""
|
||||
Flowerbox.configure do |c|
|
||||
c.test_with :jasmine
|
||||
c.spec_patterns << "**/*_spec.*"
|
||||
c.asset_paths << "lib"
|
||||
c.bare_coffeescript = true
|
||||
end
|
||||
"""
|
||||
Given I have the file "spec/javascripts/cat_spec.js.coffee" with the content:
|
||||
"""
|
||||
#= require cat
|
||||
|
||||
describe 'Cat', ->
|
||||
describe '#meow', ->
|
||||
it 'should meow', ->
|
||||
cat = new Cat()
|
||||
|
||||
expect(cat.meow()).toEqual('meow')
|
||||
"""
|
||||
Given I have the file "lib/cat.js.coffee" with the content:
|
||||
"""
|
||||
class Cat
|
||||
meow: -> "meow"
|
||||
"""
|
||||
When I run Flowerbox with "spec/javascripts"
|
||||
Then I should have 1 test and 0 failures
|
||||
|
@ -0,0 +1,7 @@
|
||||
Given /^I have the file "([^"]*)" with the content:$/ do |file, string|
|
||||
target = File.join(@root, file)
|
||||
|
||||
FileUtils.mkdir_p File.dirname(target)
|
||||
File.open(target, 'wb') { |fh| fh.print string }
|
||||
end
|
||||
|
@ -0,0 +1,7 @@
|
||||
Then /^I should have (\d+) tests? and (\d+) failures?$/ do |tests, failures|
|
||||
parts = @output.lines.to_a.last.strip.split('/')
|
||||
|
||||
parts[0].should == tests
|
||||
parts[1].should == failures
|
||||
end
|
||||
|
10
features/step_definitions/when/i_run_flowerbox.rb
Normal file
10
features/step_definitions/when/i_run_flowerbox.rb
Normal file
@ -0,0 +1,10 @@
|
||||
When /^I run Flowerbox with "([^"]*)"$/ do |arguments|
|
||||
command = %{bundle exec bin/flowerbox test #{arguments} --pwd #{@root} 2>&1}
|
||||
puts command
|
||||
@output = %x{#{command}}
|
||||
|
||||
puts @output
|
||||
|
||||
raise StandardError.new("Flowerbox failed: #{@output}") if $?.exitstatus != 0
|
||||
end
|
||||
|
6
features/support/env.rb
Normal file
6
features/support/env.rb
Normal file
@ -0,0 +1,6 @@
|
||||
Before do
|
||||
@root = "tmp/features"
|
||||
|
||||
FileUtils.rm_rf @root
|
||||
end
|
||||
|
24
flowerbox.gemspec
Normal file
24
flowerbox.gemspec
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
require File.expand_path('../lib/flowerbox/version', __FILE__)
|
||||
|
||||
Gem::Specification.new do |gem|
|
||||
gem.authors = ["John Bintz"]
|
||||
gem.email = ["john@coswellproductions.com"]
|
||||
gem.description = %q{TODO: Write a gem description}
|
||||
gem.summary = %q{TODO: Write a gem summary}
|
||||
gem.homepage = ""
|
||||
|
||||
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
gem.files = `git ls-files`.split("\n")
|
||||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
gem.name = "flowerbox"
|
||||
gem.require_paths = ["lib"]
|
||||
gem.version = Flowerbox::VERSION
|
||||
|
||||
gem.add_development_dependency 'cucumber'
|
||||
gem.add_development_dependency 'rspec'
|
||||
gem.add_development_dependency 'jasmine-core'
|
||||
|
||||
gem.add_dependency 'flowerbox-delivery'
|
||||
gem.add_dependency 'thor'
|
||||
end
|
34
lib/flowerbox.rb
Normal file
34
lib/flowerbox.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require "flowerbox/version"
|
||||
|
||||
module Flowerbox
|
||||
module Runner
|
||||
autoload :Node, 'flowerbox/runner/node'
|
||||
end
|
||||
|
||||
class << self
|
||||
def spec_patterns
|
||||
@spec_patterns ||= []
|
||||
end
|
||||
|
||||
def asset_paths
|
||||
@asset_paths ||= []
|
||||
end
|
||||
|
||||
def test_with(what)
|
||||
@test_with = what
|
||||
end
|
||||
|
||||
def load_test_environment(sprockets)
|
||||
require "flowerbox/test_environment/#{@test_with}"
|
||||
|
||||
Flowerbox.test_environment.inject_into(sprockets)
|
||||
end
|
||||
|
||||
attr_accessor :test_environment, :bare_coffeescript
|
||||
|
||||
def configure
|
||||
yield self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
0
lib/flowerbox/jasmine.rb
Normal file
0
lib/flowerbox/jasmine.rb
Normal file
44
lib/flowerbox/runner/node.rb
Normal file
44
lib/flowerbox/runner/node.rb
Normal file
@ -0,0 +1,44 @@
|
||||
require 'tempfile'
|
||||
|
||||
module Flowerbox
|
||||
module Runner
|
||||
class Node
|
||||
def self.run(files)
|
||||
new(files).run
|
||||
end
|
||||
|
||||
def initialize(files)
|
||||
@files = files
|
||||
end
|
||||
|
||||
def run
|
||||
file = Tempfile.new("node")
|
||||
file.print template
|
||||
file.close
|
||||
|
||||
system %{node #{file.path}}
|
||||
|
||||
$?.exitstatus
|
||||
end
|
||||
|
||||
def template
|
||||
<<-JS
|
||||
var fs = require('fs');
|
||||
var window = this;
|
||||
|
||||
#{template_files.join("\n")}
|
||||
#{start_test_environment}
|
||||
JS
|
||||
end
|
||||
|
||||
def template_files
|
||||
@files.collect { |file| %{eval(fs.readFileSync('#{file}', 'utf-8'));} }
|
||||
end
|
||||
|
||||
def start_test_environment
|
||||
Flowerbox.test_environment.start_for(:node)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
39
lib/flowerbox/test_environment/jasmine.rb
Normal file
39
lib/flowerbox/test_environment/jasmine.rb
Normal file
@ -0,0 +1,39 @@
|
||||
require 'jasmine-core'
|
||||
|
||||
module Flowerbox
|
||||
module TestEnvironment
|
||||
class Jasmine
|
||||
def self.inject_into(sprockets)
|
||||
sprockets.append_path(::Jasmine::Core.path)
|
||||
|
||||
sprockets.add('jasmine.js')
|
||||
sprockets.add('jasmine-html.js')
|
||||
end
|
||||
|
||||
def self.start_for(runner)
|
||||
<<-JS
|
||||
jasmine.NodeReporter = function() {}
|
||||
|
||||
jasmine.NodeReporter.prototype.reportSpecResults = function(spec) {
|
||||
console.log(spec.results().totalCount + '/' + spec.results().failedCount);
|
||||
|
||||
if (spec.results().failedCount == 0) {
|
||||
process.exit(0);
|
||||
} else {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
jasmine.NodeReporter.prototype.reportRunnerResults = function(runner) {
|
||||
}
|
||||
|
||||
jasmine.getEnv().addReporter(new jasmine.NodeReporter());
|
||||
jasmine.getEnv().execute();
|
||||
JS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Flowerbox.test_environment = Flowerbox::TestEnvironment::Jasmine
|
||||
|
3
lib/flowerbox/version.rb
Normal file
3
lib/flowerbox/version.rb
Normal file
@ -0,0 +1,3 @@
|
||||
module Flowerbox
|
||||
VERSION = "0.0.1"
|
||||
end
|
Loading…
Reference in New Issue
Block a user