Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature: evergreen runner is able to run separate files or directories of files #43

Closed
wants to merge 2 commits into from

4 participants

@gregolsen

That's said:
evergreen run spec/javascripts/foo_spec.js will execute only one foo_spec file
evergreen run spec/javascripts/models/ will execute all specs in models directory

All this in the spirit of this feature proposal

Let me know what else should be done/changed? Thanks in advance.

Changelog:

  • cwd is assumed as an Evergreen root
  • Evergreen::Runner now receive first obligatory argument - list of files/dirs
  • Evergreen::Suite.new now receive files (default is [])
  • Evergreen::FilesHelper module added with methods to find specs/templates
  • Specs added to suite_spec and files_helper_spec created
@tddium

+1

@abepetrillo
Owner

:+1: Although needs a rebase :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 2, 2011
  1. @gregolsen

    files helper module refactored, now runner receive files/dirs list in…

    gregolsen authored
    … first argument, specs extended
  2. @gregolsen

    fix to rake tasks

    gregolsen authored
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.