danieldkim-evergreen 0.4.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +155 -0
- data/bin/evergreen +18 -0
- data/config/routes.rb +3 -0
- data/lib/evergreen/application.rb +46 -0
- data/lib/evergreen/cli.rb +23 -0
- data/lib/evergreen/rails.rb +12 -0
- data/lib/evergreen/resources/evergreen.css +64 -0
- data/lib/evergreen/resources/evergreen.js +80 -0
- data/lib/evergreen/runner.rb +151 -0
- data/lib/evergreen/server.rb +22 -0
- data/lib/evergreen/spec.rb +55 -0
- data/lib/evergreen/suite.rb +44 -0
- data/lib/evergreen/tasks.rb +6 -0
- data/lib/evergreen/template.rb +28 -0
- data/lib/evergreen/version.rb +3 -0
- data/lib/evergreen/version.rb~ +3 -0
- data/lib/evergreen/views/layout.erb +19 -0
- data/lib/evergreen/views/list.erb +9 -0
- data/lib/evergreen/views/spec.erb +38 -0
- data/lib/evergreen.rb +35 -0
- data/lib/tasks/evergreen.rake +7 -0
- data/spec/evergreen_spec.rb +24 -0
- data/spec/meta_spec.rb +50 -0
- data/spec/runner_spec.rb +33 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/spec_spec.rb +28 -0
- data/spec/suite1/public/jquery.js +152 -0
- data/spec/suite1/public/styles.css +3 -0
- data/spec/suite1/spec/javascripts/bar_spec.js +0 -0
- data/spec/suite1/spec/javascripts/coffeescript_spec.coffee +7 -0
- data/spec/suite1/spec/javascripts/failing_spec.js +12 -0
- data/spec/suite1/spec/javascripts/foo_spec.js +0 -0
- data/spec/suite1/spec/javascripts/invalid_coffee_spec.coffee +1 -0
- data/spec/suite1/spec/javascripts/slow_spec.coffee +8 -0
- data/spec/suite1/spec/javascripts/spec_helper.coffee +1 -0
- data/spec/suite1/spec/javascripts/spec_helper.js +1 -0
- data/spec/suite1/spec/javascripts/templates/another_template.html +1 -0
- data/spec/suite1/spec/javascripts/templates/one_template.html +1 -0
- data/spec/suite1/spec/javascripts/templates_spec.js +47 -0
- data/spec/suite1/spec/javascripts/testing_spec.js +11 -0
- data/spec/suite1/spec/javascripts/transactions_spec.js +14 -0
- data/spec/suite1/spec/javascripts/with_helper_spec.js +9 -0
- data/spec/suite2/config/evergreen.rb +5 -0
- data/spec/suite2/public_html/foo.js +1 -0
- data/spec/suite2/spec/awesome_spec.js +12 -0
- data/spec/suite2/spec/failing_spec.js +5 -0
- data/spec/suite2/templates/foo.html +1 -0
- data/spec/suite_spec.rb +26 -0
- data/spec/template_spec.rb +22 -0
- metadata +216 -0
data/README.rdoc
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
= Evergreen
|
2
|
+
|
3
|
+
"Because green is the new Blue(Ridge)"
|
4
|
+
|
5
|
+
Evergreen is a tool to run javascript unit tests for client side JavaScript. It combines a server which allows you to serve up and run your specs in a browser, as well as a runner which uses Capybara and any of its drivers to run your specs. Evergreen uses the Jasmine unit testing framework for JavaScript.
|
6
|
+
|
7
|
+
http://github.com/jnicklas/evergreen
|
8
|
+
|
9
|
+
== Philosophy
|
10
|
+
|
11
|
+
Evergreen is a unit testing tool. Its purpose is to test JavaScript in isolation from your application. If you need a tool that tests how your JavaScript integrates with your application you should use an integration testing framework, such as {Capybara}[http://github.com/jnicklas/capybara].
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
Install as a Ruby gem:
|
16
|
+
|
17
|
+
gem install evergreen
|
18
|
+
|
19
|
+
== Usage
|
20
|
+
|
21
|
+
Evergreen assumes a file and directory structure, place all your javascript code inside ./public and all spec files inside ./spec/javascripts. All spec files should end in _spec.js. For example:
|
22
|
+
|
23
|
+
public/widget.js
|
24
|
+
spec/javascripts/widget_spec.js
|
25
|
+
|
26
|
+
You can require files from the public directory inside your spec file:
|
27
|
+
|
28
|
+
require('/widget.js')
|
29
|
+
|
30
|
+
describe('a widget', function() {
|
31
|
+
...
|
32
|
+
});
|
33
|
+
|
34
|
+
You can now look at your spec files inside a browser by starting up the Evergreen server:
|
35
|
+
|
36
|
+
evergreen serve
|
37
|
+
|
38
|
+
Alternatively you can run the specs headlessly by running:
|
39
|
+
|
40
|
+
evergreen run
|
41
|
+
|
42
|
+
== Integrating with Rails 3
|
43
|
+
|
44
|
+
Add Evergreen to your Gemfile:
|
45
|
+
|
46
|
+
gem 'evergreen', :require => 'evergreen/rails'
|
47
|
+
|
48
|
+
Start your rails application and navigate to /evergreen. You should now see a list of all spec files, click on one to run it.
|
49
|
+
|
50
|
+
There's a rake task provided for you that you can use to run your specs:
|
51
|
+
|
52
|
+
rake spec:javascripts
|
53
|
+
|
54
|
+
== Integrating with Rails 2
|
55
|
+
|
56
|
+
Add the following line to your Rakefile:
|
57
|
+
|
58
|
+
require 'evergreen/tasks'
|
59
|
+
|
60
|
+
This will give you the `spec:javascripts` rake task. Note that mounting is not possible under Rails 2 and that `require 'evergreen/rails'` will fail.
|
61
|
+
|
62
|
+
== Configuration
|
63
|
+
|
64
|
+
By default, Evergreen uses Selenium to run your specs and assumes a certain directory structure. If this standard is fine for you, then you don't need to do anything else. If you need to configure Evergreen to suit your needs, Evergreen will automatically look for and load the following files:
|
65
|
+
|
66
|
+
config/evergreen.rb
|
67
|
+
.evergreen
|
68
|
+
~/.evergreen
|
69
|
+
|
70
|
+
The content of these files could look like this:
|
71
|
+
|
72
|
+
require 'capybara/envjs'
|
73
|
+
|
74
|
+
Evergreen.configure do |config|
|
75
|
+
config.driver = :envjs
|
76
|
+
config.public_dir = 'public_html'
|
77
|
+
config.template_dir = 'templates'
|
78
|
+
config.spec_dir = 'spec'
|
79
|
+
end
|
80
|
+
|
81
|
+
== Transactions
|
82
|
+
|
83
|
+
One problem often faced when writing unit tests for client side code is that changes to the page are not reverted for the next example, so that successive examples become dependent on each other. Evergreen adds a special div to your page with an id of test. This div is automatically emptied before each example. You should avoid appending markup to the page body and instead append it to this test div:
|
84
|
+
|
85
|
+
describe('transactions', function() {
|
86
|
+
it("should add stuff in one test...", function() {
|
87
|
+
$('#test').append('<h1 id="added">New Stuff</h1>');
|
88
|
+
expect($('#test h1#added').length).toEqual(1);
|
89
|
+
});
|
90
|
+
|
91
|
+
it("... should have been removed before the next starts", function() {
|
92
|
+
expect($('#test h1#added').length).toEqual(0);
|
93
|
+
});
|
94
|
+
});
|
95
|
+
|
96
|
+
== Templates
|
97
|
+
|
98
|
+
Even more powerful than that, Evergreen allows you to create HTML templates to go along with your specs. Put the templates in their own folder like this:
|
99
|
+
|
100
|
+
spec/javascripts/templates/one_template.html
|
101
|
+
spec/javascripts/templates/another_template.html
|
102
|
+
|
103
|
+
You can then load the template into the test div, by calling the template function in your specs:
|
104
|
+
|
105
|
+
describe('transactions', function() {
|
106
|
+
template('one_template.html')
|
107
|
+
|
108
|
+
it("should load the template in this test", function() {
|
109
|
+
...
|
110
|
+
});
|
111
|
+
});
|
112
|
+
|
113
|
+
== Spec Helper
|
114
|
+
|
115
|
+
If you add a spec_helper file like so:
|
116
|
+
|
117
|
+
spec/javascripts/spec_helper.js
|
118
|
+
|
119
|
+
It will automatically be loaded. This is a great place for adding custom matchers and the like.
|
120
|
+
|
121
|
+
== CoffeeScript
|
122
|
+
|
123
|
+
Evergreen supports specs written in {CoffeeScript}[http://github.com/jashkenas/coffee-script]. Just name your spec file _spec.coffee and it will automatically be translated for you.
|
124
|
+
|
125
|
+
You can also add a CoffeeScript spec helper, but remember that CoffeeScript encloses individual files in a closure, if you need something you define in the spec helper to be available in your spec files, attach it to the window object:
|
126
|
+
|
127
|
+
# spec/javascripts/spec_helper.coffee
|
128
|
+
|
129
|
+
MyThing: "foo" # local to spec helper
|
130
|
+
window.MyThing: "foo" # global
|
131
|
+
|
132
|
+
== License:
|
133
|
+
|
134
|
+
(The MIT License)
|
135
|
+
|
136
|
+
Copyright (c) 2009 Jonas Nicklas
|
137
|
+
|
138
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
139
|
+
a copy of this software and associated documentation files (the
|
140
|
+
'Software'), to deal in the Software without restriction, including
|
141
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
142
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
143
|
+
permit persons to whom the Software is furnished to do so, subject to
|
144
|
+
the following conditions:
|
145
|
+
|
146
|
+
The above copyright notice and this permission notice shall be
|
147
|
+
included in all copies or substantial portions of the Software.
|
148
|
+
|
149
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
150
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
151
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
152
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
153
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
154
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
155
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/evergreen
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'evergreen'
|
6
|
+
|
7
|
+
begin
|
8
|
+
# The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
|
9
|
+
success = Evergreen::Cli.execute(ARGV.dup)
|
10
|
+
Kernel.exit(success ? 0 : 1)
|
11
|
+
rescue SystemExit => e
|
12
|
+
Kernel.exit(e.status)
|
13
|
+
rescue Exception => e
|
14
|
+
STDERR.puts("#{e.message} (#{e.class})")
|
15
|
+
STDERR.puts(e.backtrace.join("\n"))
|
16
|
+
Kernel.exit(1)
|
17
|
+
end
|
18
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Evergreen
|
2
|
+
def self.application(suite)
|
3
|
+
Rack::Builder.new do
|
4
|
+
map "/jasmine" do
|
5
|
+
use Rack::Static, :urls => ["/"], :root => File.expand_path('../jasmine/lib', File.dirname(__FILE__))
|
6
|
+
run lambda { |env| [404, {}, "No such file"]}
|
7
|
+
end
|
8
|
+
|
9
|
+
map "/resources" do
|
10
|
+
use Rack::Static, :urls => ["/"], :root => File.expand_path('resources', File.dirname(__FILE__))
|
11
|
+
run lambda { |env| [404, {}, "No such file"]}
|
12
|
+
end
|
13
|
+
|
14
|
+
map "/" do
|
15
|
+
app = Class.new(Sinatra::Base).tap do |app|
|
16
|
+
app.reset!
|
17
|
+
app.class_eval do
|
18
|
+
set :static, true
|
19
|
+
set :root, File.expand_path('.', File.dirname(__FILE__))
|
20
|
+
set :public, File.expand_path(File.join(suite.root, Evergreen.public_dir), File.dirname(__FILE__))
|
21
|
+
|
22
|
+
helpers do
|
23
|
+
def url(path)
|
24
|
+
request.env['SCRIPT_NAME'].to_s + path.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
get '/' do
|
29
|
+
@suite = suite
|
30
|
+
erb :list
|
31
|
+
end
|
32
|
+
|
33
|
+
get '/run/*' do |name|
|
34
|
+
@suite = suite
|
35
|
+
@spec = suite.get_spec(name)
|
36
|
+
@js_spec_helper = suite.get_spec('spec_helper.js')
|
37
|
+
@coffee_spec_helper = suite.get_spec('spec_helper.coffee')
|
38
|
+
erb :spec
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
run app
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Evergreen
|
2
|
+
class Cli
|
3
|
+
def self.execute(argv)
|
4
|
+
new.execute(argv)
|
5
|
+
end
|
6
|
+
|
7
|
+
def execute(argv)
|
8
|
+
command = argv.shift
|
9
|
+
root = File.expand_path(argv.shift || '.', Dir.pwd)
|
10
|
+
|
11
|
+
case command
|
12
|
+
when "serve"
|
13
|
+
Evergreen::Suite.new(root).serve
|
14
|
+
return true
|
15
|
+
when "run"
|
16
|
+
return Evergreen::Suite.new(root).run
|
17
|
+
else
|
18
|
+
puts "no such command '#{command}'"
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
body {
|
2
|
+
font-family: 'Lucida grande', 'sans-serif';
|
3
|
+
background: #f0f0f0;
|
4
|
+
}
|
5
|
+
|
6
|
+
a {
|
7
|
+
color: #00A500;
|
8
|
+
}
|
9
|
+
|
10
|
+
#page, #test, .jasmine_reporter {
|
11
|
+
width: 800px;
|
12
|
+
background: white;
|
13
|
+
-moz-border-radius: 3px;
|
14
|
+
padding: 20px;
|
15
|
+
margin: 50px auto 30px;
|
16
|
+
border: 1px solid #ddd
|
17
|
+
}
|
18
|
+
|
19
|
+
#test {
|
20
|
+
min-height: 50px;
|
21
|
+
max-height: 300px;
|
22
|
+
overflow: auto;
|
23
|
+
margin: 30px auto 30px;
|
24
|
+
}
|
25
|
+
|
26
|
+
.jasmine_reporter {
|
27
|
+
margin: 30px auto 30px;
|
28
|
+
}
|
29
|
+
|
30
|
+
#page h1 {
|
31
|
+
font-size: 24px;
|
32
|
+
margin: 0 0 15px;
|
33
|
+
}
|
34
|
+
|
35
|
+
#page a.back {
|
36
|
+
font-size: 12px;
|
37
|
+
}
|
38
|
+
|
39
|
+
#page ul {
|
40
|
+
margin: 0;
|
41
|
+
padding: 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
#page ul li {
|
45
|
+
list-style: none;
|
46
|
+
border: 1px solid #ddd;
|
47
|
+
-moz-border-radius: 3px;
|
48
|
+
margin: 10px 0;
|
49
|
+
background: #f5f5f5;
|
50
|
+
}
|
51
|
+
|
52
|
+
#page ul li a {
|
53
|
+
padding: 7px 10px;
|
54
|
+
display: block;
|
55
|
+
text-decoration: none;
|
56
|
+
}
|
57
|
+
|
58
|
+
#footer {
|
59
|
+
margin: 0 auto 30px;
|
60
|
+
width: 600px;
|
61
|
+
text-align: center;
|
62
|
+
font-size: 13px;
|
63
|
+
color: #aaa;
|
64
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
if(!this.JSON){this.JSON={};}
|
2
|
+
|
3
|
+
var Evergreen = {};
|
4
|
+
|
5
|
+
Evergreen.dots = ""
|
6
|
+
|
7
|
+
Evergreen.ReflectiveReporter = function() {
|
8
|
+
this.reportRunnerStarting = function(runner) {
|
9
|
+
Evergreen.results = [];
|
10
|
+
};
|
11
|
+
this.reportSpecResults = function(spec) {
|
12
|
+
var results = spec.results();
|
13
|
+
var item = results.getItems()[0] || {};
|
14
|
+
Evergreen.results.push({
|
15
|
+
name: spec.getFullName(),
|
16
|
+
passed: results.failedCount === 0,
|
17
|
+
message: item.message,
|
18
|
+
trace: item.trace
|
19
|
+
});
|
20
|
+
Evergreen.dots += (results.failedCount === 0) ? "." : "F";
|
21
|
+
};
|
22
|
+
this.reportRunnerResults = function(runner) {
|
23
|
+
Evergreen.done = true;
|
24
|
+
};
|
25
|
+
};
|
26
|
+
|
27
|
+
Evergreen.templates = {};
|
28
|
+
|
29
|
+
Evergreen.getResults = function() {
|
30
|
+
return JSON.stringify(Evergreen.results);
|
31
|
+
};
|
32
|
+
|
33
|
+
beforeEach(function() {
|
34
|
+
document.getElementById('test').innerHTML = "";
|
35
|
+
});
|
36
|
+
|
37
|
+
var template = function(name) {
|
38
|
+
beforeEach(function() {
|
39
|
+
document.getElementById('test').innerHTML = Evergreen.templates[name]
|
40
|
+
});
|
41
|
+
};
|
42
|
+
|
43
|
+
var require = function(file) {
|
44
|
+
document.write('<script type="text/javascript" src="' + file + '"></script>');
|
45
|
+
};
|
46
|
+
|
47
|
+
var stylesheet = function(file) {
|
48
|
+
document.write('<link rel="stylesheet" type="text/css" href="' + file + '"/>');
|
49
|
+
};
|
50
|
+
|
51
|
+
// === JSON ===
|
52
|
+
|
53
|
+
(function(){function f(n){return n<10?'0'+n:n;}
|
54
|
+
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
|
55
|
+
f(this.getUTCMonth()+1)+'-'+
|
56
|
+
f(this.getUTCDate())+'T'+
|
57
|
+
f(this.getUTCHours())+':'+
|
58
|
+
f(this.getUTCMinutes())+':'+
|
59
|
+
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
|
60
|
+
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
|
61
|
+
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
|
62
|
+
if(typeof rep==='function'){value=rep.call(holder,key,value);}
|
63
|
+
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
|
64
|
+
gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
|
65
|
+
v=partial.length===0?'[]':gap?'[\n'+gap+
|
66
|
+
partial.join(',\n'+gap)+'\n'+
|
67
|
+
mind+']':'['+partial.join(',')+']';gap=mind;return v;}
|
68
|
+
if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
|
69
|
+
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
|
70
|
+
mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
|
71
|
+
if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
|
72
|
+
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
|
73
|
+
return str('',{'':value});};}
|
74
|
+
if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
|
75
|
+
return reviver.call(holder,key,value);}
|
76
|
+
text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
|
77
|
+
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
|
78
|
+
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
|
79
|
+
throw new SyntaxError('JSON.parse');};}}());
|
80
|
+
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Evergreen
|
2
|
+
class Runner
|
3
|
+
class Example
|
4
|
+
def initialize(row)
|
5
|
+
@row = row
|
6
|
+
end
|
7
|
+
|
8
|
+
def passed?
|
9
|
+
@row['passed']
|
10
|
+
end
|
11
|
+
|
12
|
+
def failure_message
|
13
|
+
unless passed?
|
14
|
+
msg = []
|
15
|
+
msg << " Failed: #{@row['name']}"
|
16
|
+
msg << " #{@row['message']}"
|
17
|
+
if @row['trace']['stack']
|
18
|
+
match_data = @row['trace']['stack'].match(/\/run\/(.*\.js)/)
|
19
|
+
msg << " in #{match_data[1]}" if match_data[1]
|
20
|
+
end
|
21
|
+
msg.join("\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class SpecRunner
|
27
|
+
attr_reader :runner, :spec
|
28
|
+
|
29
|
+
def initialize(runner, spec)
|
30
|
+
@runner = runner
|
31
|
+
@spec = spec
|
32
|
+
end
|
33
|
+
|
34
|
+
def session
|
35
|
+
runner.session
|
36
|
+
end
|
37
|
+
|
38
|
+
def io
|
39
|
+
runner.io
|
40
|
+
end
|
41
|
+
|
42
|
+
def run
|
43
|
+
io.puts dots
|
44
|
+
io.puts failure_messages
|
45
|
+
io.puts "\n#{examples.size} examples, #{failed_examples.size} failures"
|
46
|
+
passed?
|
47
|
+
end
|
48
|
+
|
49
|
+
def examples
|
50
|
+
@results ||= begin
|
51
|
+
session.visit(spec.url)
|
52
|
+
|
53
|
+
previous_results = ""
|
54
|
+
|
55
|
+
session.wait_until(180) do
|
56
|
+
dots = session.evaluate_script('Evergreen.dots')
|
57
|
+
io.print dots.sub(/^#{Regexp.escape(previous_results)}/, '')
|
58
|
+
io.flush
|
59
|
+
previous_results = dots
|
60
|
+
session.evaluate_script('Evergreen.done')
|
61
|
+
end
|
62
|
+
|
63
|
+
dots = session.evaluate_script('Evergreen.dots')
|
64
|
+
io.print dots.sub(/^#{Regexp.escape(previous_results)}/, '')
|
65
|
+
|
66
|
+
JSON.parse(session.evaluate_script('Evergreen.getResults()')).map do |row|
|
67
|
+
Example.new(row)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def failed_examples
|
73
|
+
examples.select { |example| not example.passed? }
|
74
|
+
end
|
75
|
+
|
76
|
+
def passed?
|
77
|
+
examples.all? { |example| example.passed? }
|
78
|
+
end
|
79
|
+
|
80
|
+
def dots
|
81
|
+
examples; ""
|
82
|
+
end
|
83
|
+
|
84
|
+
def failure_messages
|
85
|
+
unless passed?
|
86
|
+
examples.map { |example| example.failure_message }.compact.join("\n\n")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
attr_reader :suite, :io
|
92
|
+
|
93
|
+
def initialize(suite, io=STDOUT)
|
94
|
+
@suite = suite
|
95
|
+
@io = io
|
96
|
+
end
|
97
|
+
|
98
|
+
def spec_runner(spec)
|
99
|
+
SpecRunner.new(self, spec)
|
100
|
+
end
|
101
|
+
|
102
|
+
def run
|
103
|
+
before = Time.now
|
104
|
+
|
105
|
+
io.puts ""
|
106
|
+
io.puts dots.to_s
|
107
|
+
io.puts ""
|
108
|
+
if failure_messages
|
109
|
+
io.puts failure_messages
|
110
|
+
io.puts ""
|
111
|
+
end
|
112
|
+
|
113
|
+
seconds = "%.2f" % (Time.now - before)
|
114
|
+
io.puts "Finished in #{seconds} seconds"
|
115
|
+
io.puts "#{examples.size} examples, #{failed_examples.size} failures"
|
116
|
+
passed?
|
117
|
+
end
|
118
|
+
|
119
|
+
def examples
|
120
|
+
spec_runners.map { |spec_runner| spec_runner.examples }.flatten
|
121
|
+
end
|
122
|
+
|
123
|
+
def failed_examples
|
124
|
+
examples.select { |example| not example.passed? }
|
125
|
+
end
|
126
|
+
|
127
|
+
def passed?
|
128
|
+
spec_runners.all? { |spec_runner| spec_runner.passed? }
|
129
|
+
end
|
130
|
+
|
131
|
+
def dots
|
132
|
+
spec_runners.map { |spec_runner| spec_runner.dots }.join
|
133
|
+
end
|
134
|
+
|
135
|
+
def failure_messages
|
136
|
+
unless passed?
|
137
|
+
spec_runners.map { |spec_runner| spec_runner.failure_messages }.compact.join("\n\n")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def session
|
142
|
+
@session ||= Capybara::Session.new(Evergreen.driver, suite.application)
|
143
|
+
end
|
144
|
+
|
145
|
+
protected
|
146
|
+
|
147
|
+
def spec_runners
|
148
|
+
@spec_runners ||= suite.specs.map { |spec| SpecRunner.new(self, spec) }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Evergreen
|
2
|
+
class Server
|
3
|
+
attr_reader :suite
|
4
|
+
|
5
|
+
def initialize(suite)
|
6
|
+
@suite = suite
|
7
|
+
end
|
8
|
+
|
9
|
+
def serve
|
10
|
+
server.boot
|
11
|
+
Launchy.open(server.url('/'))
|
12
|
+
sleep
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def server
|
18
|
+
@server ||= Capybara::Server.new(suite.application)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Evergreen
|
4
|
+
class Spec
|
5
|
+
class CoffeeScriptError < StandardError; end
|
6
|
+
|
7
|
+
attr_reader :name, :suite
|
8
|
+
|
9
|
+
def initialize(suite, name)
|
10
|
+
@suite = suite
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
def root
|
15
|
+
suite.root
|
16
|
+
end
|
17
|
+
|
18
|
+
def full_path
|
19
|
+
File.join(root, Evergreen.spec_dir, name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def read
|
23
|
+
if full_path =~ /\.coffee$/
|
24
|
+
stdout, stderr = Open3.popen3("coffee -p #{full_path}")[1,2].map { |b| b.read }
|
25
|
+
raise CoffeeScriptError, stderr unless stderr.empty?
|
26
|
+
stdout
|
27
|
+
else
|
28
|
+
File.read(full_path)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias_method :contents, :read
|
32
|
+
|
33
|
+
def url
|
34
|
+
"/run/#{name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def passed?
|
38
|
+
runner.passed?
|
39
|
+
end
|
40
|
+
|
41
|
+
def failure_messages
|
42
|
+
runner.failure_messages
|
43
|
+
end
|
44
|
+
|
45
|
+
def exist?
|
46
|
+
File.exist?(full_path)
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def runner
|
52
|
+
@runner ||= suite.runner.spec_runner(self)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Evergreen
|
2
|
+
class Suite
|
3
|
+
attr_reader :root, :runner, :server, :driver, :application
|
4
|
+
|
5
|
+
def initialize(root)
|
6
|
+
@root = root
|
7
|
+
|
8
|
+
paths = [
|
9
|
+
File.expand_path("config/evergreen.rb", root),
|
10
|
+
File.expand_path(".evergreen", root),
|
11
|
+
"#{ENV["HOME"]}/.evergreen"
|
12
|
+
]
|
13
|
+
paths.each { |path| load(path) if File.exist?(path) }
|
14
|
+
|
15
|
+
@runner = Runner.new(self)
|
16
|
+
@server = Server.new(self)
|
17
|
+
@application = Evergreen.application(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
runner.run
|
22
|
+
end
|
23
|
+
|
24
|
+
def serve
|
25
|
+
server.serve
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_spec(name)
|
29
|
+
Spec.new(self, name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def specs
|
33
|
+
Dir.glob(File.join(root, Evergreen.spec_dir, '*_spec.{js,coffee}')).map do |path|
|
34
|
+
Spec.new(self, File.basename(path))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def templates
|
39
|
+
Dir.glob(File.join(root, Evergreen.template_dir, '*')).map do |path|
|
40
|
+
Template.new(self, File.basename(path))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|