Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added specs for runner and spec

  • Loading branch information...
commit 967fb28d7dabb20cde586924b9047ec15a27e294 1 parent b7e477e
@jnicklas jnicklas authored
View
4 Rakefile
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
View
20 lib/evergreen/runner.rb
@@ -2,19 +2,19 @@ module Evergreen
class Runner
attr_reader :spec
- def self.run(root)
+ def self.run(root, io=STDOUT)
runners = Spec.all(root).map { |spec| new(spec) }
runners.each do |runner|
if runner.passed?
- print '.'
+ io.print '.'
else
- print 'F'
+ io.print 'F'
end
end
- puts ""
+ io.puts ""
runners.each do |runner|
- puts runner.failure_message unless runner.passed?
+ io.puts runner.failure_message unless runner.passed?
end
end
@@ -26,10 +26,6 @@ def passed?
failed_examples.empty?
end
- def failed_examples
- results.select { |row| !row.passed }
- end
-
def failure_message
failed_examples.map do |row|
<<-ERROR
@@ -40,6 +36,12 @@ def failure_message
end.join("\n\n")
end
+ protected
+
+ def failed_examples
+ results.select { |row| !row.passed }
+ end
+
def results
@results ||= begin
session = Capybara::Session.new(:envjs, Evergreen.application(spec.root))
View
1  lib/evergreen/spec.rb
@@ -21,6 +21,7 @@ def path
def read
File.read(path)
end
+ alias_method :contents, :read
def url
"/run/#{name}"
View
0  spec/fixtures/spec/javascripts/bar_spec.js
No changes.
View
12 spec/fixtures/spec/javascripts/failing_spec.js
@@ -0,0 +1,12 @@
+describe('failing spec', function() {
+
+ it("should pass", function() {
+ expect('foo').toEqual('foo');
+ });
+
+ it("should fail", function() {
+ expect('bar').toEqual('noooooo');
+ });
+
+});
+
View
0  spec/fixtures/spec/javascripts/foo_spec.js
No changes.
View
11 spec/fixtures/spec/javascripts/testing_spec.js
@@ -0,0 +1,11 @@
+describe('testing', function() {
+
+ it("should pass", function() {
+ expect('foo').toEqual('foo');
+ });
+
+ it("should also pass", function() {
+ expect('bar').toEqual('bar');
+ });
+
+});
View
35 spec/runner_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe Evergreen::Runner do
+ let(:root) { File.expand_path('fixtures', File.dirname(__FILE__)) }
+
+ context "with passing spec" do
+ let(:spec) { Evergreen::Spec.new(root, 'testing') }
+ subject { Evergreen::Runner.new(spec) }
+
+ it { should be_passed }
+ its(:spec) { should == spec }
+ its(:failure_message) { should be_empty }
+ end
+
+ context "with failing spec" do
+ let(:spec) { Evergreen::Spec.new(root, 'failing') }
+ subject { Evergreen::Runner.new(spec) }
+
+ it { should_not be_passed }
+ its(:spec) { should == spec }
+ its(:failure_message) { should include("Expected 'bar' to equal 'noooooo'") }
+ end
+
+ describe '.run' do
+ let(:buffer) { StringIO.new }
+ before { Evergreen::Runner.run(root, buffer) }
+
+ describe 'the buffer' do
+ subject { buffer.rewind; buffer.read }
+
+ it { should include('.F..') }
+ it { should include("Expected 'bar' to equal 'noooooo'") }
+ end
+ end
+end
View
1  spec/spec_helper.rb
@@ -1 +1,2 @@
require 'evergreen'
+require 'rspec'
View
15 spec/spec_spec.rb
@@ -2,10 +2,19 @@
describe Evergreen::Spec do
let(:root) { File.expand_path('fixtures', File.dirname(__FILE__)) }
+ subject { Evergreen::Spec.new(root, 'testing') }
- describe '#path' do
- it "should return the full path" do
- Evergreen::Spec.new(root, 'testing').path.should == "#{root}/spec/javascripts/testing_spec.js"
+ its(:name) { should == 'testing' }
+ its(:root) { should == root }
+ its(:path) { should == "#{root}/spec/javascripts/testing_spec.js" }
+ its(:url) { should == "/run/testing" }
+ its(:contents) { should =~ /describe\('testing'/ }
+
+ describe '.all' do
+ subject { Evergreen::Spec.all(root) }
+
+ it "should find all specs in the given root directory" do
+ subject.map(&:name).should include('testing', 'foo', 'bar')
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.