| 1 |
require File.dirname(__FILE__) + '/../../../spec_helper' |
| 2 |
require 'hpricot' |
| 3 |
require 'spec/runner/formatter/text_mate_formatter' |
| 4 |
|
| 5 |
module Spec |
| 6 |
module Runner |
| 7 |
module Formatter |
| 8 |
describe TextMateFormatter do |
| 9 |
attr_reader :root, :suffix, :expected_file |
| 10 |
before do |
| 11 |
@root = File.expand_path(File.dirname(__FILE__) + '/../../../..') |
| 12 |
@suffix = jruby? ? '-jruby' : '' |
| 13 |
@expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html" |
| 14 |
end |
| 15 |
|
| 16 |
def jruby? |
| 17 |
PLATFORM == 'java' |
| 18 |
end |
| 19 |
|
| 20 |
def produces_html_identical_to_manually_designed_document(opt) |
| 21 |
root = File.expand_path(File.dirname(__FILE__) + '/../../../..') |
| 22 |
|
| 23 |
Dir.chdir(root) do |
| 24 |
args = [ |
| 25 |
'failing_examples/mocking_example.rb', |
| 26 |
'failing_examples/diffing_spec.rb', |
| 27 |
'examples/pure/stubbing_example.rb', |
| 28 |
'examples/pure/pending_example.rb', |
| 29 |
'--format', |
| 30 |
'textmate', |
| 31 |
opt |
| 32 |
] |
| 33 |
err = StringIO.new |
| 34 |
out = StringIO.new |
| 35 |
options = ::Spec::Runner::OptionParser.parse(args, err, out) |
| 36 |
Spec::Runner::CommandLine.run(options) |
| 37 |
|
| 38 |
yield(out.string) |
| 39 |
end |
| 40 |
end |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
describe "functional spec using --diff" do |
| 63 |
it "should produce HTML identical to the one we designed manually with --diff" do |
| 64 |
produces_html_identical_to_manually_designed_document("--diff") do |html| |
| 65 |
suffix = jruby? ? '-jruby' : '' |
| 66 |
expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html" |
| 67 |
unless File.file?(expected_file) |
| 68 |
raise "There is no HTML file with expected content for this platform: #{expected_file}" |
| 69 |
end |
| 70 |
expected_html = File.read(expected_file) |
| 71 |
|
| 72 |
seconds = /\d+\.\d+ seconds/ |
| 73 |
html.gsub! seconds, 'x seconds' |
| 74 |
expected_html.gsub! seconds, 'x seconds' |
| 75 |
|
| 76 |
doc = Hpricot(html) |
| 77 |
backtraces = doc.search("div.backtrace/a") |
| 78 |
doc.search("div.backtrace").remove |
| 79 |
|
| 80 |
expected_doc = Hpricot(expected_html) |
| 81 |
expected_doc.search("div.backtrace").remove |
| 82 |
|
| 83 |
doc.inner_html.should == expected_doc.inner_html |
| 84 |
|
| 85 |
backtraces.each do |backtrace_link| |
| 86 |
backtrace_link[:href].should include("txmt://open?url=") |
| 87 |
end |
| 88 |
end |
| 89 |
end |
| 90 |
|
| 91 |
end |
| 92 |
|
| 93 |
describe "functional spec using --dry-run" do |
| 94 |
it "should produce HTML identical to the one we designed manually with --dry-run" do |
| 95 |
produces_html_identical_to_manually_designed_document("--dry-run") do |html, expected_html| |
| 96 |
html.should =~ /This was a dry-run/m |
| 97 |
end |
| 98 |
end |
| 99 |
end |
| 100 |
end |
| 101 |
end |
| 102 |
end |
| 103 |
end |