Skip to content
Browse files

Merge branch 'master' of github.com:jnicklas/evergreen

Conflicts:
  Gemfile.lock
  evergreen.gemspec
  lib/evergreen/spec.rb
  • Loading branch information...
2 parents 19b1a0a + 0402087 commit 58ab97700862b7308ebf0c1089f454b8ca510882 @jnicklas jnicklas committed
View
18 Gemfile.lock
@@ -43,16 +43,14 @@ GEM
rack-test (0.6.0)
rack (>= 1.0)
rake (0.9.2)
- rspec (2.0.0)
- rspec-core (= 2.0.0)
- rspec-expectations (= 2.0.0)
- rspec-mocks (= 2.0.0)
- rspec-core (2.0.0)
- rspec-expectations (2.0.0)
- diff-lcs (>= 1.1.2)
- rspec-mocks (2.0.0)
- rspec-core (= 2.0.0)
- rspec-expectations (= 2.0.0)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
rubyzip (0.9.4)
selenium-webdriver (0.2.1)
childprocess (>= 0.1.7)
View
64 README.rdoc
@@ -2,13 +2,19 @@
"Because green is the new Blue(Ridge)"
-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.
+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.
http://github.com/jnicklas/evergreen
== Philosophy
-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].
+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].
== Installation
@@ -18,7 +24,9 @@ Install as a Ruby gem:
== Usage
-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:
+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:
public/widget.js
spec/javascripts/widget_spec.js
@@ -31,7 +39,8 @@ You can require files from the public directory inside your spec file:
...
});
-You can now look at your spec files inside a browser by starting up the Evergreen server:
+You can now look at your spec files inside a browser by starting up the
+Evergreen server:
evergreen serve
@@ -45,7 +54,8 @@ Add Evergreen to your Gemfile:
gem 'evergreen', :require => 'evergreen/rails'
-Start your rails application and navigate to /evergreen. You should now see a list of all spec files, click on one to run it.
+Start your rails application and navigate to /evergreen. You should now see a
+list of all spec files, click on one to run it.
There's a rake task provided for you that you can use to run your specs:
@@ -57,11 +67,15 @@ Add the following line to your Rakefile:
require 'evergreen/tasks'
-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.
+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.
== Configuration
-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:
+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:
config/evergreen.rb
.evergreen
@@ -80,7 +94,12 @@ The content of these files could look like this:
== Transactions
-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:
+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:
describe('transactions', function() {
it("should add stuff in one test...", function() {
@@ -95,12 +114,14 @@ One problem often faced when writing unit tests for client side code is that cha
== Templates
-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:
+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:
spec/javascripts/templates/one_template.html
spec/javascripts/templates/another_template.html
-You can then load the template into the test div, by calling the template function in your specs:
+You can then load the template into the test div, by calling the template
+function in your specs:
describe('transactions', function() {
template('one_template.html')
@@ -116,19 +137,36 @@ If you add a spec_helper file like so:
spec/javascripts/spec_helper.js
-It will automatically be loaded. This is a great place for adding custom matchers and the like.
+It will automatically be loaded. This is a great place for adding custom
+matchers and the like.
== CoffeeScript
-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.
+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.
-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:
+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:
# spec/javascripts/spec_helper.coffee
MyThing: "foo" # local to spec helper
window.MyThing: "foo" # global
+== Development
+
+If you plan to work on Evergreen, you need to checkout the Jasmine gem, which
+is added as a git submodule. Run the following command:
+
+ git submodule update --init
+
+If you're using a version of Evergreen from git with bundler, you need to tell
+bundler to use submodules, this can be achieved with the following command:
+
+ gem 'evergreen', :submodules => true, :git => 'git://github.com/jnicklas/evergreen.git'
+
== License:
(The MIT License)
View
2 Rakefile
@@ -2,3 +2,5 @@ require 'rubygems'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
View
5 lib/evergreen.rb
@@ -21,6 +21,11 @@ def configure
yield self
end
+ def extensions(&block)
+ @extensions = block if block
+ @extensions
+ end
+
def use_defaults!
configure do |config|
config.driver = :selenium
View
2 lib/evergreen/application.rb
@@ -1,6 +1,8 @@
module Evergreen
def self.application(suite)
Rack::Builder.new do
+ instance_eval(&Evergreen.extensions) if Evergreen.extensions
+
map "/jasmine" do
use Rack::Static, :urls => ["/"], :root => File.expand_path('../jasmine/lib', File.dirname(__FILE__))
run lambda { |env| [404, {}, "No such file"]}
View
2 lib/evergreen/spec.rb
@@ -2,8 +2,6 @@
module Evergreen
class Spec
- class CoffeeScriptError < StandardError; end
-
attr_reader :name, :suite
def initialize(suite, name)
View
4 lib/evergreen/suite.rb
@@ -30,8 +30,8 @@ def get_spec(name)
end
def specs
- Dir.glob(File.join(root, Evergreen.spec_dir, '*_spec.{js,coffee}')).map do |path|
- Spec.new(self, File.basename(path))
+ Dir.glob(File.join(root, Evergreen.spec_dir, '**/*_spec.{js,coffee}')).map do |path|
+ Spec.new(self, path.gsub(File.join(root, Evergreen.spec_dir, ''), ''))
end
end
View
4 lib/evergreen/template.rb
@@ -20,6 +20,10 @@ def read
end
alias_method :contents, :read
+ def escaped_contents
+ contents.to_json.gsub("<script>", %{<scr" + "ipt>}).gsub("</script>", %{</scr" + "ipt>})
+ end
+
def exist?
File.exist?(full_path)
end
View
22 lib/evergreen/views/spec.erb
@@ -25,14 +25,16 @@
<div id="test"></div>
<script type="text/javascript">
- (function() {
- Evergreen.driver = <%= Evergreen.driver.to_json %>;
- <% @suite.templates.each do |template| %>
- Evergreen.templates[<%= template.name.to_json %>] = <%= template.read.to_json %>;
- <% end %>
- var jasmineEnv = jasmine.getEnv();
- jasmineEnv.addReporter(new jasmine.TrivialReporter());
- jasmineEnv.addReporter(new Evergreen.ReflectiveReporter());
- jasmineEnv.execute();
- })();
+ // <![CDATA[
+ (function() {
+ Evergreen.driver = <%= Evergreen.driver.to_json %>;
+ <% @suite.templates.each do |template| %>
+ Evergreen.templates[<%= template.name.to_json %>] = <%= template.escaped_contents %>;
+ <% end %>
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.addReporter(new jasmine.TrivialReporter());
+ jasmineEnv.addReporter(new Evergreen.ReflectiveReporter());
+ jasmineEnv.execute();
+ })();
+ // ]]>
</script>
View
5 spec/evergreen_spec.rb
@@ -21,4 +21,9 @@
page.should have_content("2 specs, 1 failure")
page.should have_content("Expected 'bar' to equal 'noooooo'.")
end
+
+ it "should add extensions to Evergreen" do
+ visit('/awesome')
+ page.should have_content('Totally awesome')
+ end
end
View
2 spec/runner_spec.rb
@@ -14,7 +14,7 @@
it { should include('.F..') }
it { should include("Expected 'bar' to equal 'noooooo'") }
- it { should include("17 examples, 3 failures") }
+ it { should include("18 examples, 3 failures") }
end
end
View
6 spec/spec_helper.rb
@@ -9,6 +9,12 @@
TEST_DRIVER = :webkit
+Evergreen.extensions do
+ map "/awesome" do
+ run lambda { |env| [200, {}, "<html><body>Totally awesome</body></html>"]}
+ end
+end
+
Capybara.app = Evergreen::Suite.new(File.expand_path('suite1', File.dirname(__FILE__))).application
Capybara.default_driver = TEST_DRIVER
View
0 spec/suite1/spec/javascripts/libs/lucid_spec.js
No changes.
View
0 spec/suite1/spec/javascripts/models/game_spec.js
No changes.
View
1 spec/suite1/spec/javascripts/templates/escape.html
@@ -0,0 +1 @@
+<script>var foo = 0;</script>
View
3 spec/suite1/spec/javascripts/templates/script_tags.html
@@ -0,0 +1,3 @@
+<h1 id="script-tags"></h1>
+
+<script></script>
View
8 spec/suite1/spec/javascripts/templates_spec.js
@@ -33,6 +33,14 @@ describe('templates', function() {
});
});
+ describe('with template with script tags', function() {
+ template('script_tags.html')
+
+ it("should append the template to the test div", function() {
+ expect($('#test h1#script-tags').length).toEqual(1);
+ });
+ });
+
});
describe('stylesheet', function() {
View
4 spec/suite_spec.rb
@@ -13,8 +13,8 @@
end
describe '#specs' do
- it "should find all specs in the given root directory" do
- subject.specs.map(&:name).should include('testing_spec.js', 'foo_spec.js', 'bar_spec.js', 'coffeescript_spec.coffee')
+ 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')
end
end
View
10 spec/template_spec.rb
@@ -20,3 +20,13 @@
end
end
+
+describe Evergreen::Template, "escaping" do
+ let(:root) { File.expand_path('suite1', File.dirname(__FILE__)) }
+ let(:suite) { Evergreen::Suite.new(root) }
+ subject { Evergreen::Template.new(suite, 'escape.html') }
+
+ it "escapes contents" do
+ subject.escaped_contents.strip.should == %{"<scr" + "ipt>var foo = 0;</scr" + "ipt>\\n"}
+ end
+end

0 comments on commit 58ab977

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