mocha-color 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mocha-color.gemspec
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ ## mocha-color
2
+
3
+ Default mocha output is hard to read sometimes, mainly when there are lots of expectations. mocha-color colorize some pieces of that output, helping you to get your expectations fixed more quickly.
4
+
5
+ ## Installation
6
+
7
+ $ gem install mocha-color
8
+
9
+ require "mocha-color"
10
+
11
+ or using Gemfile
12
+
13
+ gem "mocha-color"
14
+
15
+ ## Maintainer
16
+
17
+ * Rafael Souza - [rafaelss.com](http://rafaelss.com)
18
+
19
+ ## License
20
+
21
+ (The MIT License)
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ require "mocha-color/cardinality"
2
+ require "mocha-color/expectation"
3
+ require "mocha-color/mockery"
4
+ require "test/unit/color"
5
+
6
+ module Mocha
7
+ module Color
8
+
9
+ RESET_COLOR = Test::Unit::Color.new("reset")
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require "mocha/cardinality"
2
+
3
+ module Mocha
4
+
5
+ class Cardinality
6
+
7
+ alias :original_mocha_inspect :mocha_inspect
8
+
9
+ def mocha_inspect
10
+ color = Test::Unit::Color.new("yellow")
11
+ reset_color = Mocha::Color::RESET_COLOR
12
+
13
+ "%s%s%s" % [color.escape_sequence, original_mocha_inspect, reset_color.escape_sequence ]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ require "mocha/expectation"
2
+
3
+ module Mocha
4
+ class Expectation
5
+
6
+ def mocha_inspect
7
+ color = Test::Unit::Color.new("yellow")
8
+ reset_color = Mocha::Color::RESET_COLOR
9
+
10
+ count_message = case @invocation_count
11
+ when 0 then "not yet invoked"
12
+ when 1 then "already invoked once"
13
+ when 2 then "already invoked twice"
14
+ else "already invoked #{@invocation_count} times"
15
+ end
16
+
17
+ message = "#{@cardinality.mocha_inspect}, "
18
+ message << "%s%s%s" % [ color.escape_sequence, count_message, reset_color.escape_sequence ]
19
+ message << ": "
20
+ message << method_signature
21
+ message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty?
22
+ message
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require "mocha/mockery"
2
+
3
+ module Mocha
4
+ class Mockery
5
+
6
+ def mocha_inspect
7
+ unsatisfied_color = Test::Unit::Color.new("red", :foreground => false) + Test::Unit::Color.new("white")
8
+ satisfied_color = Test::Unit::Color.new("green", :foreground => false) + Test::Unit::Color.new("white")
9
+ reset_color = Mocha::Color::RESET_COLOR
10
+
11
+ message = ""
12
+ message << "\n%s%s%s" % [ unsatisfied_color.escape_sequence, "unsatisfied expectations:", reset_color.escape_sequence ]
13
+ message << "\n- #{unsatisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless unsatisfied_expectations.empty?
14
+ message << "\n%s%s%s" % [ satisfied_color.escape_sequence, "satisfied expectations:", reset_color.escape_sequence ]
15
+ message << "\n- #{satisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless satisfied_expectations.empty?
16
+ message << "states:\n- #{state_machines.map { |sm| sm.mocha_inspect }.join("\n- ")}" unless state_machines.empty?
17
+ message
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Mocha
2
+ module Color
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mocha-color/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mocha-color"
7
+ s.version = Mocha::Color::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Rafael Souza"]
10
+ s.email = ["me@rafaelss.com"]
11
+ s.homepage = "http://github.com/rafaelss/mocha-color"
12
+ s.summary = %q{Add some colors to mocha output}
13
+ s.description = %q{This gem try to turn mocha output more readable, adding some colors}
14
+
15
+ s.add_runtime_dependency "mocha", "~> 0.9.10"
16
+ s.add_runtime_dependency "test-unit", "~> 2.1.2"
17
+ s.add_development_dependency "minitest", "~> 2.0.2"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,8 @@
1
+ require "mocha-color/cardinality"
2
+
3
+ class TestCardinality < MiniTest::Unit::TestCase
4
+
5
+ def test_should_describe_cardinality
6
+ assert_equal "\e[33mallowed any number of times\e[0m", Mocha::Cardinality.at_least(0).mocha_inspect
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require "mocha-color/expectation"
2
+
3
+ class TestExpectation < MiniTest::Unit::TestCase
4
+
5
+ def test_mocha_inspect
6
+ expectation = Mocha::Expectation.new(nil, :expected_method).with(1, 2, 3).at_least_once
7
+ assert_match(/\e\[33mexpected at least once\e\[0m, \e\[33mnot yet invoked\e\[0m/i, expectation.mocha_inspect)
8
+
9
+ expectation = Mocha::Expectation.new(nil, :expected_method).times(2)
10
+ 1.times { expectation.invoke }
11
+ assert_match(/\e\[33mexpected exactly twice\e\[0m, \e\[33malready invoked once\e\[0m/i, expectation.mocha_inspect)
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require "mocha-color/mockery"
2
+
3
+ class TestMockery < MiniTest::Unit::TestCase
4
+
5
+ def test_mocha_inspect
6
+ mockery = Mocha::Mockery.instance
7
+ assert_match(/\e\[41;37munsatisfied expectations:\e\[0m\n\e\[42;37msatisfied expectations:\e\[0m/, mockery.mocha_inspect)
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ require "bundler"
2
+ Bundler.require
3
+
4
+ require "minitest/mock"
5
+ require "minitest/autorun"
6
+ require "./test/mocha-color/test_cardinality"
7
+ require "./test/mocha-color/test_expectation"
8
+ require "./test/mocha-color/test_mockery"
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mocha-color
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Rafael Souza
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-31 00:00:00 -02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mocha
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 10
31
+ version: 0.9.10
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: test-unit
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 1
45
+ - 2
46
+ version: 2.1.2
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: minitest
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 2
59
+ - 0
60
+ - 2
61
+ version: 2.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ description: This gem try to turn mocha output more readable, adding some colors
66
+ email:
67
+ - me@rafaelss.com
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - README.md
78
+ - Rakefile
79
+ - lib/mocha-color.rb
80
+ - lib/mocha-color/cardinality.rb
81
+ - lib/mocha-color/expectation.rb
82
+ - lib/mocha-color/mockery.rb
83
+ - lib/mocha-color/version.rb
84
+ - mocha-color.gemspec
85
+ - test/mocha-color/test_cardinality.rb
86
+ - test/mocha-color/test_expectation.rb
87
+ - test/mocha-color/test_mockery.rb
88
+ - test/test_all.rb
89
+ has_rdoc: true
90
+ homepage: http://github.com/rafaelss/mocha-color
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 2955878610926327846
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 2955878610926327846
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.3.7
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Add some colors to mocha output
123
+ test_files:
124
+ - test/mocha-color/test_cardinality.rb
125
+ - test/mocha-color/test_expectation.rb
126
+ - test/mocha-color/test_mockery.rb
127
+ - test/test_all.rb