Skip to content

Commit

Permalink
Make directory structure configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas authored and Nicklas Ramhöj committed Oct 21, 2010
1 parent 65b4bf3 commit a0a52f9
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 9 deletions.
15 changes: 11 additions & 4 deletions lib/evergreen.rb
Expand Up @@ -16,14 +16,21 @@ module Evergreen
autoload :Template, 'evergreen/template'

class << self
attr_accessor :driver
attr_accessor :driver, :public_dir, :template_dir, :spec_dir

def configure
yield self
end

def use_defaults!
configure do |config|
config.driver = :selenium
config.public_dir = 'public'
config.spec_dir = 'spec/javascripts'
config.template_dir = 'spec/javascripts/templates'
end
end
end
end

Evergreen.configure do |config|
config.driver = :selenium
end
Evergreen.use_defaults!
2 changes: 1 addition & 1 deletion lib/evergreen/application.rb
Expand Up @@ -17,7 +17,7 @@ def self.application(suite)
app.class_eval do
set :static, true
set :root, File.expand_path('.', File.dirname(__FILE__))
set :public, File.expand_path(File.join(suite.root, 'public'), File.dirname(__FILE__))
set :public, File.expand_path(File.join(suite.root, Evergreen.public_dir), File.dirname(__FILE__))

helpers do
def url(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/evergreen/spec.rb
Expand Up @@ -12,7 +12,7 @@ def root
end

def full_path
File.join(root, 'spec/javascripts', name)
File.join(root, Evergreen.spec_dir, name)
end

def read
Expand Down
4 changes: 2 additions & 2 deletions lib/evergreen/suite.rb
Expand Up @@ -30,13 +30,13 @@ def get_spec(name)
end

def specs
Dir.glob(File.join(root, 'spec/javascripts', '*_spec.{js,coffee}')).map do |path|
Dir.glob(File.join(root, Evergreen.spec_dir, '*_spec.{js,coffee}')).map do |path|
Spec.new(self, File.basename(path))
end
end

def templates
Dir.glob(File.join(root, 'spec/javascripts/templates', '*')).map do |path|
Dir.glob(File.join(root, Evergreen.template_dir, '*')).map do |path|
Template.new(self, File.basename(path))
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/evergreen/template.rb
Expand Up @@ -12,7 +12,7 @@ def root
end

def full_path
File.join(root, 'spec/javascripts/templates', name)
File.join(root, Evergreen.template_dir, name)
end

def read
Expand Down
14 changes: 14 additions & 0 deletions spec/meta_spec.rb
Expand Up @@ -27,5 +27,19 @@
it { should_not pass }
end
end

context "with modified setup" do
let(:root) { File.expand_path('suite2', File.dirname(__FILE__)) }

context "with awesome spec" do
let(:template) { 'awesome_spec.js' }
it { should pass }
end

context "with failing spec" do
let(:template) { 'failing_spec.js' }
it { should_not pass }
end
end
end

1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -37,6 +37,7 @@ def pass
RSpec.configure do |config|
config.include EvergreenMatchers
config.before do
Evergreen.use_defaults!
Evergreen.driver = TEST_DRIVER
end
end
5 changes: 5 additions & 0 deletions spec/suite2/config/evergreen.rb
@@ -0,0 +1,5 @@
Evergreen.configure do |config|
config.public_dir = 'public_html'
config.template_dir = 'templates'
config.spec_dir = 'spec'
end
1 change: 1 addition & 0 deletions spec/suite2/public_html/foo.js
@@ -0,0 +1 @@
var foo = "The Foo";
12 changes: 12 additions & 0 deletions spec/suite2/spec/awesome_spec.js
@@ -0,0 +1,12 @@
require('/foo.js')

describe('awesome', function() {
template('foo.html');

it('requires public files', function() {
expect(foo).toEqual('The Foo');
});
it('loads templates', function() {
expect(document.getElementById('foo').innerHTML).toEqual('The foo template');
});
});
5 changes: 5 additions & 0 deletions spec/suite2/spec/failing_spec.js
@@ -0,0 +1,5 @@
describe('failing', function() {
it('fails', function() {
expect('llama').toEqual('monkey');
});
});
1 change: 1 addition & 0 deletions spec/suite2/templates/foo.html
@@ -0,0 +1 @@
<div id="foo">The foo template</div>

0 comments on commit a0a52f9

Please sign in to comment.