Skip to content
Browse files

Merge patch from greg olsen (gregolsen/evergreen).

  • Loading branch information...
1 parent 1b20715 commit 4fce105057511be9e8a3949205befcec645621f7 William Josephson committed Apr 3, 2012
View
3 .gitignore
@@ -1,3 +1,4 @@
.rvmrc
.bundle
-Gemfile.lock
+.tddium*
+.tddium
View
89 Gemfile.lock
@@ -0,0 +1,89 @@
+PATH
+ remote: .
+ specs:
+ evergreen (1.0.0)
+ capybara (~> 1.0)
+ coffee-script
+ json_pure
+ launchy
+ sinatra (~> 1.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.2.7)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ capybara-webkit (0.11.0)
+ capybara (>= 1.0.0, < 1.2)
+ json
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
+ coderay (1.0.5)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.2.0)
+ diff-lcs (1.1.3)
+ execjs (1.3.0)
+ multi_json (~> 1.0)
+ ffi (1.0.11)
+ json (1.6.6)
+ json_pure (1.6.6)
+ launchy (2.1.0)
+ addressable (~> 2.2.6)
+ libv8 (3.3.10.4)
+ method_source (0.7.1)
+ mime-types (1.18)
+ multi_json (1.2.0)
+ nokogiri (1.5.2)
+ pry (0.9.8.4)
+ coderay (~> 1.0.5)
+ method_source (~> 0.7.1)
+ slop (>= 2.4.4, < 3)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rubyzip (0.9.6.1)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ slop (2.4.4)
+ therubyracer (0.10.0)
+ libv8 (~> 3.3.10)
+ tilt (1.3.3)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara-webkit (~> 0.7)
+ evergreen!
+ pry
+ rake
+ rspec (~> 2.0)
+ therubyracer (~> 0.9)
View
1 lib/evergreen.rb
@@ -7,6 +7,7 @@
require 'json'
module Evergreen
+ autoload :FilesHelper, 'evergreen/files_helper'
autoload :Cli, 'evergreen/cli'
autoload :Server, 'evergreen/server'
autoload :Runner, 'evergreen/runner'
View
4 lib/evergreen/cli.rb
@@ -6,7 +6,7 @@ def self.execute(argv)
def execute(argv)
command = argv.shift
- Evergreen.root = File.expand_path(argv.shift || '.', Dir.pwd)
+ Evergreen.root = File.expand_path('.', Dir.pwd)
# detect Rails apps
if File.exist?(File.join(Evergreen.root, 'config/environment.rb'))
@@ -19,7 +19,7 @@ def execute(argv)
Evergreen::Server.new.serve
return true
when "run"
- return Evergreen::Runner.new.run
+ return Evergreen::Runner.new(argv).run
else
puts "no such command '#{command}'"
return false
View
35 lib/evergreen/files_helper.rb
@@ -0,0 +1,35 @@
+module Evergreen
+ module FilesHelper
+ PATTERN = '**/*_spec.{js,coffee}'
+
+ class << self
+
+ def root
+ Evergreen.root
+ end
+
+ def find_specs(files)
+ files.empty? ? find_all_spec_files : find_spec_files(files)
+ end
+
+ def find_spec_files(files)
+ files.map do |file|
+ if File.directory?(file)
+ Dir.glob(File.join(root, "#{file}/{#{PATTERN}}"))
+ else
+ path = File.absolute_path(file, root)
+ File.exist?(path) ? path : nil
+ end
+ end.flatten.compact
+ end
+
+ def find_all_spec_files
+ Dir.glob(File.join(root, Evergreen.spec_dir, PATTERN))
+ end
+
+ def find_templates
+ Dir.glob(File.join(root, Evergreen.template_dir, '*'))
+ end
+ end
+ end
+end
View
7 lib/evergreen/runner.rb
@@ -85,10 +85,11 @@ def failure_messages
end
end
- attr_reader :suite, :io
+ attr_reader :suite, :io, :options
- def initialize(io=STDOUT)
+ def initialize(options, io=STDOUT)
@io = io
+ @options = options
end
def spec_runner(spec)
@@ -139,7 +140,7 @@ def session
end
def suite
- @suite ||= Evergreen::Suite.new
+ @suite ||= Evergreen::Suite.new(@options)
end
protected
View
17 lib/evergreen/suite.rb
@@ -1,8 +1,11 @@
module Evergreen
+
class Suite
- attr_reader :driver
- def initialize
+ attr_reader :driver, :files
+
+ def initialize(files = [])
+ @files = files
paths = [
File.expand_path("config/evergreen.rb", root),
File.expand_path(".evergreen", root),
@@ -19,20 +22,26 @@ def mounted_at
Evergreen.mounted_at
end
+ def files_helper
+ Evergreen::FilesHelper
+ end
+
def get_spec(name)
Spec.new(self, name)
end
def specs
- Dir.glob(File.join(root, Evergreen.spec_dir, '**/*_spec.{js,coffee}')).map do |path|
+ files_helper.find_specs(@files).map do |path|
Spec.new(self, path.gsub(File.join(root, Evergreen.spec_dir, ''), ''))
end
end
def templates
- Dir.glob(File.join(root, Evergreen.template_dir, '*')).map do |path|
+ files_helper.find_templates.map do |path|
Template.new(self, File.basename(path))
end
end
+
end
+
end
View
2 lib/evergreen/tasks.rb
@@ -4,7 +4,7 @@
namespace :spec do
desc "Run JavaScript specs via Evergreen"
task :javascripts => :environment do
- result = Evergreen::Runner.new.run
+ result = Evergreen::Runner.new([]).run
Kernel.exit(1) unless result
end
end
View
2 lib/tasks/evergreen.rake
@@ -2,7 +2,7 @@
namespace :spec do
desc "Run JavaScript specs via Evergreen"
task :javascripts => :environment do
- result = Evergreen::Runner.new.run
+ result = Evergreen::Runner.new([]).run
Kernel.exit(1) unless result
end
end
View
38 spec/files_helper_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe Evergreen::FilesHelper do
+ describe '.root' do
+ subject { Evergreen::FilesHelper.root }
+ it { should == File.expand_path('suite1', File.dirname(__FILE__)) }
+ end
+
+ describe '.find_all_spec_files' do
+ subject { Evergreen::FilesHelper.find_all_spec_files }
+
+ it "should return full paths of spec files" do
+ files = %w(testing_spec.js foo_spec.js bar_spec.js libs/lucid_spec.js models/game_spec.js)
+ paths = files.map { |file| File.expand_path('suite1/spec/javascripts/' + file, File.dirname(__FILE__)) }
+ subject.should include(*paths)
+ end
+ end
+
+ describe '.find_spec_files' do
+ subject { Evergreen::FilesHelper.find_spec_files(files) }
+
+ context "directory" do
+ let(:files) { %w(spec/javascripts/libs) }
+ it { should have(1).path }
+ end
+
+ context "files" do
+ let(:files) { %w(spec/javascripts/foo_spec.js spec/javascripts/models/game_spec.js) }
+ it { should have(2).paths }
+ end
+
+ context "incorrect file passed" do
+ let(:files) { %w(non_existent.js) }
+ it { should have(:no).paths }
+ end
+
+ end
+end
View
3 spec/runner_spec.rb
@@ -2,7 +2,8 @@
describe Evergreen::Runner do
let(:suite) { Evergreen::Suite.new }
- let(:runner) { Evergreen::Runner.new(buffer) }
+ let(:args) { [] }
+ let(:runner) { Evergreen::Runner.new(args, buffer) }
let(:buffer) { StringIO.new }
describe '#run' do
View
2 spec/spec_helper.rb
@@ -20,7 +20,7 @@ module EvergreenMatchers
class PassSpec # :nodoc:
def matches?(actual)
@actual = actual
- @runner = Evergreen::Runner.new(StringIO.new).spec_runner(@actual)
+ @runner = Evergreen::Runner.new([], StringIO.new).spec_runner(@actual)
@runner.passed?
end
View
19 spec/suite_spec.rb
@@ -1,7 +1,8 @@
require 'spec_helper'
describe Evergreen::Suite do
- subject { Evergreen::Suite.new }
+ let(:files) { [] }
+ subject { Evergreen::Suite.new(files) }
its(:root) { should == File.expand_path('suite1', File.dirname(__FILE__)) }
@@ -13,13 +14,25 @@
describe '#specs' do
it "should find all specs recursively in the given root directory" do
- subject.specs.map(&:name).should include('testing_spec.js', 'foo_spec.js', 'bar_spec.js', 'libs/lucid_spec.js', 'models/game_spec.js')
+ subject.specs.map(&:name).should include(*%w(testing_spec.js foo_spec.js bar_spec.js libs/lucid_spec.js models/game_spec.js))
end
end
describe '#templates' do
it "should find all specs in the given root directory" do
- subject.templates.map(&:name).should include('one_template.html', 'another_template.html')
+ subject.templates.map(&:name).should include(*%w(one_template.html another_template.html))
end
end
+
+ context "files passed" do
+ let(:files) { %w(spec/javascripts/testing_spec.js spec/javascripts/libs/lucid_spec.js) }
+ it { should have(2).specs }
+
+ describe '#specs' do
+ it "should find specs passed to suite" do
+ subject.specs.map(&:name).should include(*%w(testing_spec.js libs/lucid_spec.js))
+ end
+ end
+ end
+
end

0 comments on commit 4fce105

Please sign in to comment.
Something went wrong with that request. Please try again.