Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add textmate formatter

  • Loading branch information...
commit 7b84ffe29fc9a96b14633738b52cd127d5fc23eb 1 parent b2c73ee
David Chelimsky dchelimsky authored
2  lib/rspec/core/configuration.rb
View
@@ -183,6 +183,8 @@ def formatter=(formatter_to_use)
RSpec::Core::Formatters::DocumentationFormatter
when 'h', 'html'
RSpec::Core::Formatters::HtmlFormatter
+ when 't', 'textmate'
+ RSpec::Core::Formatters::TextMateFormatter
when 'progress'
RSpec::Core::Formatters::ProgressFormatter
else
1  lib/rspec/core/formatters.rb
View
@@ -4,4 +4,5 @@
require 'rspec/core/formatters/documentation_formatter'
require 'rspec/core/formatters/progress_formatter'
require 'rspec/core/formatters/html_formatter'
+require 'rspec/core/formatters/text_mate_formatter'
18 lib/rspec/core/formatters/text_mate_formatter.rb
View
@@ -0,0 +1,18 @@
+require 'rspec/core/formatters/html_formatter'
+
+module RSpec
+ module Core
+ module Formatters
+ # Formats backtraces so they're clickable by TextMate
+ class TextMateFormatter < HtmlFormatter
+ def backtrace_line(line)
+ if line = super(line)
+ line.sub!(/([^:]*\.rb):(\d*)/) do
+ "<a href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2}</a> "
+ end
+ end
+ end
+ end
+ end
+ end
+end
2  lib/rspec/core/option_parser.rb
View
@@ -44,6 +44,8 @@ def parser(options)
parser.on('-f', '--format FORMATTER', 'Choose a formatter',
' [p]rogress (default - dots)',
' [d]ocumentation (group and example names)',
+ ' [h]tml',
+ ' [t]extmate',
' custom formatter class name') do |o|
options[:formatter] = o
end
6 spec/rspec/core/formatters/html_formatter_spec.rb
View
@@ -29,6 +29,12 @@ module Formatters
File.read(expected_file)
end
+ before do
+ RSpec.configuration.stub(:require_files_to_run) do
+ RSpec.configuration.files_to_run.map {|f| load File.expand_path(f) }
+ end
+ end
+
# Uncomment this group temporarily in order to overwrite the expected
# with actual. Use with care!!!
# describe "file generator" do
280 spec/rspec/core/formatters/text_mate_formatted-1.8.7.html
View
@@ -0,0 +1,280 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>RSpec results</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta http-equiv="Expires" content="-1" />
+ <meta http-equiv="Pragma" content="no-cache" />
+ <style type="text/css">
+ body {
+ margin: 0;
+ padding: 0;
+ background: #fff;
+ font-size: 80%;
+ }
+ </style>
+ <script type="text/javascript">
+ // <![CDATA[
+function moveProgressBar(percentDone) {
+ document.getElementById("rspec-header").style.width = percentDone +"%";
+}
+function makeRed(element_id) {
+ document.getElementById(element_id).style.background = '#C40D0D';
+ document.getElementById(element_id).style.color = '#FFFFFF';
+}
+
+function makeYellow(element_id) {
+ if (element_id == "rspec-header" && document.getElementById(element_id).style.background != '#C40D0D')
+ {
+ document.getElementById(element_id).style.background = '#FAF834';
+ document.getElementById(element_id).style.color = '#000000';
+ }
+ else
+ {
+ document.getElementById(element_id).style.background = '#FAF834';
+ document.getElementById(element_id).style.color = '#000000';
+ }
+}
+
+ // ]]>
+ </script>
+ <style type="text/css">
+#rspec-header {
+ background: #65C400; color: #fff; height: 4em;
+}
+
+.rspec-report h1 {
+ margin: 0px 10px 0px 10px;
+ padding: 10px;
+ font-family: "Lucida Grande", Helvetica, sans-serif;
+ font-size: 1.8em;
+ position: absolute;
+}
+
+#summary {
+ margin: 0; padding: 5px 10px;
+ font-family: "Lucida Grande", Helvetica, sans-serif;
+ text-align: right;
+ top: 0px;
+ right: 0px;
+ float:right;
+}
+
+#summary p {
+ margin: 0 0 0 2px;
+}
+
+#summary #totals {
+ font-size: 1.2em;
+}
+
+.example_group {
+ margin: 0 10px 5px;
+ background: #fff;
+}
+
+dl {
+ margin: 0; padding: 0 0 5px;
+ font: normal 11px "Lucida Grande", Helvetica, sans-serif;
+}
+
+dt {
+ padding: 3px;
+ background: #65C400;
+ color: #fff;
+ font-weight: bold;
+}
+
+dd {
+ margin: 5px 0 5px 5px;
+ padding: 3px 3px 3px 18px;
+}
+
+dd.spec.passed {
+ border-left: 5px solid #65C400;
+ border-bottom: 1px solid #65C400;
+ background: #DBFFB4; color: #3D7700;
+}
+
+dd.spec.failed {
+ border-left: 5px solid #C20000;
+ border-bottom: 1px solid #C20000;
+ color: #C20000; background: #FFFBD3;
+}
+
+dd.spec.not_implemented {
+ border-left: 5px solid #FAF834;
+ border-bottom: 1px solid #FAF834;
+ background: #FCFB98; color: #131313;
+}
+
+dd.spec.pending_fixed {
+ border-left: 5px solid #0000C2;
+ border-bottom: 1px solid #0000C2;
+ color: #0000C2; background: #D3FBFF;
+}
+
+.backtrace {
+ color: #000;
+ font-size: 12px;
+}
+
+a {
+ color: #BE5C00;
+}
+
+/* Ruby code, style similar to vibrant ink */
+.ruby {
+ font-size: 12px;
+ font-family: monospace;
+ color: white;
+ background-color: black;
+ padding: 0.1em 0 0.2em 0;
+}
+
+.ruby .keyword { color: #FF6600; }
+.ruby .constant { color: #339999; }
+.ruby .attribute { color: white; }
+.ruby .global { color: white; }
+.ruby .module { color: white; }
+.ruby .class { color: white; }
+.ruby .string { color: #66FF00; }
+.ruby .ident { color: white; }
+.ruby .method { color: #FFCC00; }
+.ruby .number { color: white; }
+.ruby .char { color: white; }
+.ruby .comment { color: #9933CC; }
+.ruby .symbol { color: white; }
+.ruby .regex { color: #44B4CC; }
+.ruby .punct { color: white; }
+.ruby .escape { color: white; }
+.ruby .interp { color: white; }
+.ruby .expr { color: white; }
+
+.ruby .offending { background-color: gray; }
+.ruby .linenum {
+ width: 75px;
+ padding: 0.1em 1em 0.2em 0;
+ color: #000000;
+ background-color: #FFFBD3;
+}
+
+ </style>
+</head>
+<body>
+<div class="rspec-report">
+
+<div id="rspec-header">
+ <div id="label">
+ <h1>RSpec Code Examples</h1>
+ </div>
+
+ <div id="summary">
+ <p id="totals">&nbsp;</p>
+ <p id="duration">&nbsp;</p>
+ </div>
+</div>
+
+<div class="results">
+<div class="example_group">
+ <dl>
+ <dt id="example_group_1">pending spec with no implementation</dt>
+ <script type="text/javascript">makeYellow('rspec-header');</script>
+ <script type="text/javascript">makeYellow('example_group_1');</script>
+ <script type="text/javascript">moveProgressBar('20.0');</script>
+ <dd class="spec not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ </dl>
+</div>
+<div class="example_group">
+ <dl>
+ <dt id="example_group_2">pending command with block format</dt>
+ </dl>
+</div>
+<div class="example_group">
+ <dl>
+ <dt id="example_group_3">with content that would fail</dt>
+ <script type="text/javascript">makeYellow('rspec-header');</script>
+ <script type="text/javascript">makeYellow('example_group_3');</script>
+ <script type="text/javascript">moveProgressBar('40.0');</script>
+ <dd class="spec not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: No reason given)</span></dd>
+ </dl>
+</div>
+<div class="example_group">
+ <dl>
+ <dt id="example_group_4">with content that would pass</dt>
+ <script type="text/javascript">makeRed('rspec-header');</script>
+ <script type="text/javascript">makeRed('example_group_4');</script>
+ <script type="text/javascript">moveProgressBar('60.0');</script>
+ <dd class="spec pending_fixed">
+ <span class="failed_spec_name">fails</span>
+ <div class="failure" id="failure_0">
+ <div class="message"><pre>RSpec::Core::PendingExampleFixedError</pre></div>
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=19">./spec/rspec/core/resources/formatter_specs.rb:19</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=23">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:23</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a> :in `open'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `chdir'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `instance_eval'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `sandboxed'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a> </pre></div>
+ <pre class="ruby"><code><span class="linenum">11</span> <span class="keyword">rescue</span> <span class="constant">Exception</span> <span class="punct">=&gt;</span> <span class="ident">e</span>
+<span class="linenum">12</span> <span class="keyword">end</span>
+<span class="offending"><span class="linenum">13</span> <span class="keyword">raise</span> <span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Core</span><span class="punct">::</span><span class="constant">PendingExampleFixedError</span><span class="punct">.</span><span class="ident">new</span> <span class="keyword">if</span> <span class="ident">result</span></span>
+<span class="linenum">14</span> <span class="keyword">end</span>
+<span class="linenum">15</span> <span class="ident">throw</span> <span class="symbol">:pending_declared_in_example</span><span class="punct">,</span> <span class="ident">message</span></code></pre>
+ </div>
+ </dd>
+ </dl>
+</div>
+<div class="example_group">
+ <dl>
+ <dt id="example_group_5">passing spec</dt>
+ <script type="text/javascript">moveProgressBar('80.0');</script>
+ <dd class="spec passed"><span class="passed_spec_name">passes</span></dd>
+ </dl>
+</div>
+<div class="example_group">
+ <dl>
+ <dt id="example_group_6">failing spec</dt>
+ <script type="text/javascript">makeRed('example_group_6');</script>
+ <script type="text/javascript">moveProgressBar('100.0');</script>
+ <dd class="spec failed">
+ <span class="failed_spec_name">fails</span>
+ <div class="failure" id="failure_0">
+ <div class="message"><pre>
+expected 2
+ got 1
+
+(compared using ==)
+</pre></div>
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=34">./spec/rspec/core/resources/formatter_specs.rb:34</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=23">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:23</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a> :in `open'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `chdir'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a>
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `instance_eval'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `sandboxed'
+<a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a> </pre></div>
+ <pre class="ruby"><code><span class="linenum">27</span> <span class="keyword">end</span>
+<span class="linenum">28</span>
+<span class="offending"><span class="linenum">29</span> <span class="keyword">raise</span><span class="punct">(</span><span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Expectations</span><span class="punct">::</span><span class="constant">ExpectationNotMetError</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">message</span><span class="punct">))</span></span>
+<span class="linenum">30</span> <span class="keyword">end</span></code></pre>
+ </div>
+ </dd>
+ </dl>
+</div>
+<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>x seconds</strong>";</script>
+<script type="text/javascript">document.getElementById('totals').innerHTML = "5 examples, 2 failures, 2 pending";</script>
+</div>
+</div>
+</body>
+</html>
67 spec/rspec/core/formatters/text_mate_formatter_spec.rb
View
@@ -0,0 +1,67 @@
+require 'spec_helper'
+require 'nokogiri'
+
+module RSpec
+ module Core
+ module Formatters
+ describe TextMateFormatter do
+ let(:jruby?) { ::RUBY_PLATFORM == 'java' }
+ let(:root) { File.expand_path("#{File.dirname(__FILE__)}/../../../..") }
+ let(:suffix) { jruby? ? '-jruby' : '' }
+
+ let(:expected_file) do
+ "#{File.dirname(__FILE__)}/text_mate_formatted-#{::RUBY_VERSION}#{suffix}.html"
+ end
+
+ let(:generated_html) do
+ options = RSpec::Core::ConfigurationOptions.new(
+ %w[spec/rspec/core/resources/formatter_specs.rb --format textmate]
+ )
+ options.parse_options
+ err, out = StringIO.new, StringIO.new
+ command_line = RSpec::Core::CommandLine.new(options)
+ command_line.run(err, out)
+ out.string.gsub /\d+\.\d+ seconds/, 'x seconds'
+ end
+
+ let(:expected_html) do
+ raise "There is no HTML file with expected content for this platform: #{expected_file}" unless File.file?(expected_file)
+ File.read(expected_file)
+ end
+
+ before do
+ RSpec.configuration.stub(:require_files_to_run) do
+ RSpec.configuration.files_to_run.map {|f| load File.expand_path(f) }
+ end
+ end
+
+ # Uncomment this group temporarily in order to overwrite the expected
+ # with actual. Use with care!!!
+ # describe "file generator" do
+ # it "generates a new comparison file" do
+ # Dir.chdir(root) do
+ # File.open(expected_file, 'w') {|io| io.write(generated_html)}
+ # end
+ # end
+ # end
+
+ it "should produce HTML identical to the one we designed manually" do
+ Dir.chdir(root) do
+ actual_doc = Nokogiri::HTML(generated_html)
+ backtrace_lines = actual_doc.search("div.backtrace a")
+ actual_doc.search("div.backtrace").remove
+
+ expected_doc = Nokogiri::HTML(expected_html)
+ expected_doc.search("div.backtrace").remove
+
+ actual_doc.inner_html.should == expected_doc.inner_html
+
+ backtrace_lines.each do |backtrace_line|
+ backtrace_line['href'].should include("txmt://open?url=")
+ end
+ end
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.