Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add html formatter spec pulled from rspec-1

  • Loading branch information...
commit 7cc1a6cca837aeb563436894d57fdf188e0c5fd3 1 parent 1c1d570
David Chelimsky dchelimsky authored
1  Gemfile
View
@@ -11,6 +11,7 @@ gem "rcov"
gem "mocha"
gem "rr"
gem "flexmock"
+gem "nokogiri"
gem "rspec-core", :path => "."
gem "rspec-expectations", :path => "../rspec-expectations"
gem "rspec-mocks", :path => "../rspec-mocks"
263 spec/rspec/core/formatters/html_formatted-1.8.7.html
View
@@ -0,0 +1,263 @@
+<?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>./spec/rspec/core/resources/formatter_specs.rb:19</pre></div>
+ <pre class="ruby"><code><span class="linenum">11</span> rescue Exception => e
+<span class="linenum">12</span> end
+<span class="offending"><span class="linenum">13</span> raise RSpec::Core::PendingExampleFixedError.new if result</span>
+<span class="linenum">14</span> end
+<span class="linenum">15</span> throw :pending_declared_in_example, message
+<span class="linenum">16</span><span class="comment"># gem install syntax to get syntax highlighting</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>./spec/rspec/core/resources/formatter_specs.rb:34</pre></div>
+ <pre class="ruby"><code><span class="linenum">27</span> end
+<span class="linenum">28</span>
+<span class="offending"><span class="linenum">29</span> raise(RSpec::Expectations::ExpectationNotMetError.new(message))</span>
+<span class="linenum">30</span> end
+<span class="linenum">31</span>
+<span class="linenum">32</span><span class="comment"># gem install syntax to get syntax highlighting</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>
70 spec/rspec/core/formatters/html_formatter_spec.rb
View
@@ -0,0 +1,70 @@
+# require 'spec_helper'
+
+begin # See rescue all the way at the bottom
+
+ require 'nokogiri' # Needed to compare generated with wanted HTML
+ require 'rspec/core/formatters/html_formatter'
+
+ module RSpec
+ module Core
+ module Formatters
+ describe HtmlFormatter do
+
+ def jruby?
+ ::RUBY_PLATFORM == 'java'
+ end
+
+ attr_reader :root, :expected_file, :expected_html
+
+ before do
+ @root = File.expand_path("#{File.dirname(__FILE__)}/../../../..")
+ suffix = jruby? ? '-jruby' : ''
+ @expected_file = "#{File.dirname(__FILE__)}/html_formatted-#{::RUBY_VERSION}#{suffix}.html"
+ raise "There is no HTML file with expected content for this platform: #{expected_file}" unless File.file?(expected_file)
+ @expected_html = File.read(expected_file)
+ end
+
+ let(:generated_html) do
+ seconds = /\d+\.\d+ seconds/
+ html = `bundle exec rspec spec/rspec/core/resources/formatter_specs.rb --format html`
+ html.gsub seconds, 'x seconds'
+ end
+
+ # Uncomment this line 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)
+ actual_backtraces = actual_doc.search("div.backtrace").collect {|e| e.at("pre").inner_html}
+ actual_doc.css("div.backtrace").remove
+
+ expected_doc = Nokogiri::HTML(expected_html)
+ expected_backtraces = expected_doc.search("div.backtrace").collect {|e| e.at("pre").inner_html}
+ expected_doc.search("div.backtrace").remove
+
+ actual_doc.inner_html.should == expected_doc.inner_html
+
+ expected_backtraces.each_with_index do |expected_line, i|
+ expected_path, expected_line_number, expected_suffix = expected_line.split(':')
+ actual_path, actual_line_number, actual_suffix = actual_backtraces[i].split(':')
+ File.expand_path(actual_path).should == File.expand_path(expected_path)
+ actual_line_number.should == expected_line_number
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+rescue LoadError
+ warn "nokogiri not loaded -- skipping HtmlFormatter specs"
+end
36 spec/rspec/core/resources/formatter_specs.rb
View
@@ -0,0 +1,36 @@
+# Deliberately named _specs.rb to avoid being loaded except when specified
+
+
+describe "pending spec with no implementation" do
+ it "is pending"
+end
+
+describe "pending command with block format" do
+ context "with content that would fail" do
+ it "is pending" do
+ pending do
+ 1.should eq(2)
+ end
+ end
+ end
+
+ context "with content that would pass" do
+ it "fails" do
+ pending do
+ 1.should eq(1)
+ end
+ end
+ end
+end
+
+describe "passing spec" do
+ it "passes" do
+ 1.should eq(1)
+ end
+end
+
+describe "failing spec" do
+ it "fails" do
+ 1.should eq(2)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.