Skip to content

Commit

Permalink
bugfix: unit tests are now fine
Browse files Browse the repository at this point in the history
  • Loading branch information
dgvncsz0f committed Dec 3, 2012
1 parent b4caf22 commit f27577c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .rvmrc
@@ -1 +1 @@
rvm use 1.8.7@rspec-extra-formaters --create
rvm use 1.9.3@rspec-extra-formaters --create
69 changes: 37 additions & 32 deletions README.rst
Expand Up @@ -4,41 +4,46 @@ RSpec Formatters

::

$ rake format=tap
ok 1 - TapFormatter should initialize the counter to 0
ok 2 - TapFormatter example_passed should increment the counter and use the full_description attribute
ok 3 - TapFormatter example_failed should increment the counter and use the full_description attribute
ok 4 - TapFormatter example_pending should do the same as example_failed with TODO comment
ok 5 - TapFormatter dump_summary should print the number of tests if there were tests
ok 6 - TapFormatter dump_summary should print nothing if there were not tests
ok 7 - JUnitFormatter should initialize the tests with failures and success
ok 8 - JUnitFormatter example_passed should push the example obj into success list
ok 9 - JUnitFormatter example_failed should push the example obj into failures list
ok 10 - JUnitFormatter example_pending should do the same as example_failed
ok 11 - JUnitFormatter read_failure should ignore if there is no exception
ok 12 - JUnitFormatter read_failure should read message and backtrace from the example
ok 13 - JUnitFormatter dump_summary should print the junit xml
1..13
$ rake format=tap | sed 1d
TAP version 13
1..15
ok 1 - JUnitFormatter should initialize the tests with failures and success
ok 2 - JUnitFormatter example_passed should push the example obj into success list
ok 3 - JUnitFormatter example_failed should push the example obj into failures list
ok 4 - JUnitFormatter example_pending should push the example obj into the skipped list
ok 5 - JUnitFormatter read_failure should ignore if there is no exception
ok 6 - JUnitFormatter read_failure should attempt to read exception if exception encountered is nil
ok 7 - JUnitFormatter read_failure should read message and backtrace from the example
ok 8 - JUnitFormatter dump_summary should print the junit xml
ok 9 - JUnitFormatter dump_summary should escape characteres <,>,&," before building xml
ok 10 - TapFormatter should initialize the counter to 0
ok 11 - TapFormatter example_passed should increment the counter and use the full_description attribute
ok 12 - TapFormatter example_failed should increment the counter and use the full_description attribute
ok 13 - TapFormatter example_pending should do the same as example_failed with SKIP comment
ok 14 - TapFormatter dump_summary should print the number of tests if there were tests
ok 15 - TapFormatter dump_summary should print nothing if there were not tests

::

$ rake format=junit
<?xml version="1.0" encoding="utf-8" ?>
<testsuite errors="0" failures="0" tests="13" time="0.019992" timestamp="2011-01-21T23:07:41-02:00">
<properties />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/tap_formatter_spec.rb" name="TapFormatter should initialize the counter to 0" time="0.001298" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/tap_formatter_spec.rb" name="TapFormatter example_passed should increment the counter and use the full_description attribute" time="0.001546" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/tap_formatter_spec.rb" name="TapFormatter example_failed should increment the counter and use the full_description attribute" time="0.001427" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/tap_formatter_spec.rb" name="TapFormatter example_pending should do the same as example_failed" time="0.001456" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/tap_formatter_spec.rb" name="TapFormatter dump_summary should print the number of tests if there were tests" time="0.00177" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/tap_formatter_spec.rb" name="TapFormatter dump_summary should print nothing if there were not tests" time="0.000398" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter should initialize the tests with failures and success" time="0.000859" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter example_passed should push the example obj into success list" time="0.000829" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter example_failed should push the example obj into failures list" time="0.000778" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter example_pending should do the same as example_failed" time="0.000758" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter read_failure should ignore if there is no exception" time="0.00119" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter read_failure should read message and backtrace from the example" time="0.001823" />
<testcase classname="/home/dsouza/dev/github/rspec_formatters/spec/junit_formatter_spec.rb" name="JUnitFormatter dump_summary should print the junit xml" time="0.003813" />
$ rake format=junit | sed 1d
<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" skipped="0" tests="15" time="0.008132403" timestamp="2012-12-03T17:52:59-02:00">
<properties/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter should initialize the tests with failures and success" time="0.00258258"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter example_passed should push the example obj into success list" time="0.000210973"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter example_failed should push the example obj into failures list" time="0.00019527"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter example_pending should push the example obj into the skipped list" time="0.000194194"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter read_failure should ignore if there is no exception" time="0.000330483"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter read_failure should attempt to read exception if exception encountered is nil" time="0.000629093"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter read_failure should read message and backtrace from the example" time="0.00054028"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter dump_summary should print the junit xml" time="0.000990184"/>
<testcase classname="./spec/rspec-extra-formatters/junit_formatter_spec.rb" name="JUnitFormatter dump_summary should escape characteres &lt;,&gt;,&amp;,&quot; before building xml" time="0.00040997"/>
<testcase classname="./spec/rspec-extra-formatters/tap_formatter_spec.rb" name="TapFormatter should initialize the counter to 0" time="7.3649e-05"/>
<testcase classname="./spec/rspec-extra-formatters/tap_formatter_spec.rb" name="TapFormatter example_passed should increment the counter and use the full_description attribute" time="0.000205454"/>
<testcase classname="./spec/rspec-extra-formatters/tap_formatter_spec.rb" name="TapFormatter example_failed should increment the counter and use the full_description attribute" time="0.00029728"/>
<testcase classname="./spec/rspec-extra-formatters/tap_formatter_spec.rb" name="TapFormatter example_pending should do the same as example_failed with SKIP comment" time="0.000325112"/>
<testcase classname="./spec/rspec-extra-formatters/tap_formatter_spec.rb" name="TapFormatter dump_summary should print the number of tests if there were tests" time="0.000372799"/>
<testcase classname="./spec/rspec-extra-formatters/tap_formatter_spec.rb" name="TapFormatter dump_summary should print nothing if there were not tests" time="6.3588e-05"/>
</testsuite>

Using it
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec-extra-formatters/tap_formatter.rb
Expand Up @@ -35,7 +35,7 @@ class TapFormatter < RSpec::Core::Formatters::BaseFormatter
OK = 'ok'
NOT_OK = 'not ok'
TODO = '# TODO '
SKIP = '# SKIP '
SKIP = '# SKIP '

def initialize(output)
super(output)
Expand Down Expand Up @@ -76,7 +76,7 @@ def dump_summary(duration, example_count, failure_count, pending_count)
private
def tap_example_output(ok, example, modifier='')
@total += 1
output.puts("#{ok} #{@total} - #{modifier} #{example.metadata[:full_description]}")
output.puts("#{ok} #{@total} - #{modifier}#{example.metadata[:full_description]}")
end

end
20 changes: 15 additions & 5 deletions spec/rspec-extra-formatters/tap_formatter_spec.rb
Expand Up @@ -55,29 +55,36 @@

it "should increment the counter and use the full_description attribute" do
example = mock("example")
example.stub(:exception) { "exception message" }
example.should_receive(:metadata).and_return({:full_description => "foobar"})

output = StringIO.new
f = TapFormatter.new(output)
f.example_failed(example)

f.total.should eql(1)
output.string.should == "not ok 1 - foobar\n"
output.string.should == <<-EOF
not ok 1 - foobar
---
exception message
...
EOF
end
end

describe "example_pending" do

it "should do the same as example_failed with TODO comment" do
it "should do the same as example_failed with SKIP comment" do
example = mock("example")
example.stub(:exception) { "exception message" }
example.should_receive(:metadata).and_return({:full_description => "foobar"})

output = StringIO.new
f = TapFormatter.new(output)
f.example_pending(example)

f.total.should eql(1)
output.string.should == "not ok 1 - # TODO foobar\n"
output.string.should == "not ok 1 - # SKIP foobar\n"
end

end
Expand All @@ -86,6 +93,7 @@

it "should print the number of tests if there were tests" do
example = mock("example")
example.stub(:exception) { "exception message" }
example.should_receive(:metadata).and_return({:full_description => "foobar"})
example.should_receive(:metadata).and_return({:full_description => "foobar"})
example.should_receive(:metadata).and_return({:full_description => "foobar"})
Expand All @@ -100,8 +108,10 @@
output.string.should == <<-EOF
ok 1 - foobar
not ok 2 - foobar
not ok 3 - # TODO foobar
1..3
---
exception message
...
not ok 3 - # SKIP foobar
EOF
end

Expand Down

0 comments on commit f27577c

Please sign in to comment.