clintegracon 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25fcbf3498d6a95409593f24de5d6885bf1d7e33
4
- data.tar.gz: a6e78918b216994abe40dba9c275fba234f903d0
3
+ metadata.gz: cd5f7726a433dc1feba13bbe11a573bffd341122
4
+ data.tar.gz: 75ff10a192573273b4a09d0d5052c1510f4b51bd
5
5
  SHA512:
6
- metadata.gz: 32aa4fc119befca2f816fa6566c525de80a05dbaadf870b687021ae80549c2ef688437d020771d297eedeec8687b12443d4a65b5ba9a7130a2a2b1245226eb35
7
- data.tar.gz: 6a8ae5276a8eecbeff4e024820de3f9098d2f1f0e2f21e1c5664e23dd9d47fd6c9bea2bf6d9d8fd0541c3482523b294b310abb73719e9b5c74735d61554a21bc
6
+ metadata.gz: d49ed2a50832e23ba62d59d96bc96b18d1d22e9b8af5d95ad35e3bd446cbd171d8a7a71385cb5d235bea5ded61573889f19732e3d88519bc7257f588526d0bc2
7
+ data.tar.gz: ac8a342022a0f022ff1c35feea8459be9560ade8b5f3e5175933bb2b57723d43f3504d351c6d8fd98148bad01e71c9d7be6e2ebf1fd60d72f4276a6a7b4581f6
data/README.md CHANGED
@@ -146,6 +146,14 @@ This is not fixed, but if yours differ, you have to change paths accordingly.
146
146
  ![Bacon Example Terminal Output](/../assets/term-output-bacon.png?raw=true)
147
147
 
148
148
 
149
+ ## Acknowledgement
150
+
151
+ This gem was inspired by the idea behind the integration tests of the
152
+ [CocoaPods](cp-main)'s main project and was integrated there.
153
+ See [the integration in CocoaPods][cp-integration] for a real-world example with
154
+ very extensive usage of all features.
155
+
156
+
149
157
  ## Contributing
150
158
 
151
159
  1. Fork it
@@ -153,3 +161,6 @@ This is not fixed, but if yours differ, you have to change paths accordingly.
153
161
  3. Commit your changes (`git commit -am 'Add some feature'`)
154
162
  4. Push to the branch (`git push origin my-new-feature`)
155
163
  5. Create new Pull Request
164
+
165
+ [cp-main]: https://github.com/CocoaPods/CocoaPods
166
+ [cp-integration]: https://github.com/CocoaPods/CocoaPods/blob/master/spec/integration.rb
@@ -119,13 +119,15 @@ module CLIntegracon::Adapter::Bacon
119
119
  file_tree_spec_context.spec(spec_dir).run do |spec|
120
120
  instance_eval &block
121
121
 
122
+ formatter = spec.formatter.lazy
123
+
122
124
  spec.compare do |diff|
123
125
  it diff.relative_path.to_s do
124
- diff.produced.should.satisfy(spec.formatter.describe_missing_file(diff.relative_path)) do
126
+ diff.produced.should.satisfy(formatter.describe_missing_file(diff.relative_path)) do
125
127
  diff.produced.exist?
126
128
  end
127
129
 
128
- diff.produced.should.satisfy(spec.formatter.describe_file_diff(diff)) do
130
+ diff.produced.should.satisfy(formatter.describe_file_diff(diff)) do
129
131
  diff.is_equal?
130
132
  end
131
133
  end
@@ -133,7 +135,7 @@ module CLIntegracon::Adapter::Bacon
133
135
 
134
136
  spec.check_unexpected_files do |files|
135
137
  it "should not produce unexpected files" do
136
- files.should.satisfy(spec.formatter.describe_unexpected_files(files)) do
138
+ files.should.satisfy(formatter.describe_unexpected_files(files)) do
137
139
  files.size == 0
138
140
  end
139
141
  end
@@ -1,6 +1,82 @@
1
1
  require 'colored'
2
2
 
3
3
  module CLIntegracon
4
+
5
+ # A LazyString is constructed by a block, but only evaluated when needed
6
+ class LazyString
7
+
8
+ # @return [Proc]
9
+ # the closure which will be used to build the string
10
+ attr_reader :proc
11
+
12
+ # Initialize a LazyString
13
+ #
14
+ # @param [Block () -> (String)] block
15
+ # the block which returns a string, called by #to_s
16
+ #
17
+ def initialize(&block)
18
+ @proc = block
19
+ end
20
+
21
+ # Calls the underlying proc to build the string. The result will be
22
+ # memorized, so subsequent calls of this method will not cause that the
23
+ # proc will be called again.
24
+ #
25
+ # @return [String]
26
+ #
27
+ def to_str
28
+ @string ||= proc.call().to_s
29
+ end
30
+
31
+ alias :to_s :to_str
32
+
33
+ end
34
+
35
+ # A LazyStringProxy returns a LazyString for each call, which delegates the
36
+ # call as soon as the result is needed to the underlying formatter.
37
+ class LazyStringProxy
38
+
39
+ # @return [Formatter]
40
+ # the formatter used to build the string
41
+ attr_reader :formatter
42
+
43
+ # Initialize a LazyStringProxy, which returns for each call to an
44
+ # underlying formatter a new LazyString, whose #to_s method will evaluate
45
+ # to the result of the original call delegated to the formatter.
46
+ #
47
+ # @param [Formatter] formatter
48
+ # the formatter
49
+ #
50
+ def initialize(formatter)
51
+ @formatter = formatter
52
+ end
53
+
54
+ # Remember the call delegated to #formatter in a closure on an anonymous
55
+ # object, defined as method :to_s.
56
+ #
57
+ # @return [#to_s]
58
+ #
59
+ def method_missing(method, *args, &block)
60
+ return LazyString.new do
61
+ @formatter.send(method, *args, &block)
62
+ end
63
+ end
64
+
65
+ # Respond to all methods, which are beginning with `describe_` to
66
+ # which the #formatter also responds.
67
+ #
68
+ # @return [Bool]
69
+ #
70
+ def respond_to?(method)
71
+ if /^describe_/.match(method) && @formatter.respond_to?(method)
72
+ true
73
+ else
74
+ super
75
+ end
76
+ end
77
+
78
+ end
79
+
4
80
  class Formatter
5
81
 
6
82
  # @return [FileTreeSpec]
@@ -17,6 +93,15 @@ module CLIntegracon
17
93
  @spec = spec
18
94
  end
19
95
 
96
+ # Return a proxy, which returns formatted string, evaluated first
97
+ # if #to_s is called on this instance.
98
+ #
99
+ # @return [LazyStringProxy]
100
+ #
101
+ def lazy
102
+ LazyStringProxy.new(self)
103
+ end
104
+
20
105
  # Return a description text for an expectation that a file path
21
106
  # was expected to exist, but is missing.
22
107
  #
@@ -1,3 +1,3 @@
1
1
  module CLIntegracon
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,5 +1,4 @@
1
- require 'CLIntegracon'
2
- require 'mocha-on-bacon'
1
+ require File.expand_path('../../spec_helper', __FILE__)
3
2
 
4
3
  describe 'CLIntegracon::Adapter::Bacon' do
5
4
 
@@ -1,5 +1,4 @@
1
- require 'CLIntegracon'
2
- require 'mocha-on-bacon'
1
+ require File.expand_path('../spec_helper', __FILE__)
3
2
 
4
3
  describe CLIntegracon do
5
4
 
@@ -0,0 +1,124 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe CLIntegracon::Formatter do
4
+
5
+ def subject
6
+ CLIntegracon::Formatter
7
+ end
8
+
9
+ before do
10
+ @spec = stub('Spec', spec_folder: '$spec_folder')
11
+ end
12
+
13
+ describe "#initialize" do
14
+ it 'should set given spec as attribute' do
15
+ @formatter = subject.new(@spec)
16
+ @formatter.spec.should.should.eql?(@spec)
17
+ end
18
+ end
19
+
20
+ shared 'has_formatting_methods' do
21
+ describe '#respond_to?' do
22
+ it 'should respond to #describe_missing_file' do
23
+ @formatter.respond_to?(:describe_missing_file).should.be.true?
24
+ end
25
+
26
+ it 'should respond to #describe_unexpected_files' do
27
+ @formatter.respond_to?(:describe_unexpected_files).should.be.true?
28
+ end
29
+
30
+ it 'should respond to #describe_file_diff' do
31
+ @formatter.respond_to?(:describe_file_diff).should.be.true?
32
+ end
33
+ end
34
+
35
+ describe "#describe_missing_file" do
36
+ it 'should match the expected return value' do
37
+ @formatter.describe_missing_file('$missing').to_s.should.be.eql? <<-EOS.chomp
38
+ Missing file for $spec_folder:
39
+ * \e[31m$missing\e[0m
40
+ EOS
41
+ end
42
+ end
43
+
44
+ describe "#describe_unexpected_files" do
45
+ it 'should match the expected return value' do
46
+ @formatter.describe_unexpected_files(['$a', '$b']).to_s.should.be.eql? <<-EOS.chomp
47
+ Unexpected files for $spec_folder:
48
+ * \e[32m$a\e[0m
49
+ * \e[32m$b\e[0m
50
+ EOS
51
+ end
52
+ end
53
+
54
+ describe "#describe_file_diff" do
55
+ it 'should match the expected return value' do
56
+ diff = ['$before', '+ $add', '- $removed', '$after']
57
+ diff.stubs(relative_path: '$relative_path')
58
+ @formatter.describe_file_diff(diff, 20).to_s.should.be.eql? <<-EOS
59
+ File comparison error `$relative_path` for $spec_folder:
60
+ --- DIFF -----------
61
+ $before
62
+ \e[32m+ $add\e[0m
63
+ \e[31m- $removed\e[0m
64
+ $after
65
+ --- END ------------
66
+ EOS
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'has formatting methods' do
72
+ before do
73
+ @formatter = subject.new(@spec)
74
+ end
75
+
76
+ behaves_like 'has_formatting_methods'
77
+ end
78
+
79
+ describe "#lazy" do
80
+ before do
81
+ @formatter = subject.new(@spec)
82
+ end
83
+
84
+ describe '#respond_to?' do
85
+ it 'should not respond to additional methods' do
86
+ @formatter.lazy.respond_to?(:describe_foo).should.be.false?
87
+ @formatter.lazy.respond_to?(:lazy).should.be.false?
88
+ end
89
+ end
90
+
91
+ describe 'delegates to formatting methods' do
92
+ before do
93
+ @formatter = subject.new(@spec).lazy
94
+ end
95
+
96
+ behaves_like 'has_formatting_methods'
97
+ end
98
+
99
+ describe '#describe_missing_file' do
100
+ it 'should not call the method immediately' do
101
+ @formatter.expects(:describe_missing_file).never
102
+ @formatter.lazy.describe_missing_file('a')
103
+ .should.be.an.instance_of?(CLIntegracon::LazyString)
104
+ end
105
+ end
106
+
107
+ describe "#describe_unexpected_files" do
108
+ it 'should not call the method immediately' do
109
+ @formatter.expects(:describe_unexpected_files).never
110
+ @formatter.lazy.describe_unexpected_files(['a', 'b'])
111
+ .should.be.an.instance_of?(CLIntegracon::LazyString)
112
+ end
113
+ end
114
+
115
+ describe "#describe_file_diff" do
116
+ it 'should not call the method immediately' do
117
+ @formatter.expects(:describe_missing_file).never
118
+ @formatter.lazy.describe_file_diff(stub('Diff'))
119
+ .should.be.an.instance_of?(CLIntegracon::LazyString)
120
+ end
121
+ end
122
+ end
123
+
124
+ end
@@ -0,0 +1,2 @@
1
+ require 'CLIntegracon'
2
+ require 'mocha-on-bacon'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clintegracon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Rackwitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -166,6 +166,8 @@ files:
166
166
  - spec/integration/coffeemaker_sweetner_honey/before/Coffeemakerfile.yml
167
167
  - spec/unit/adapter/bacon_spec.rb
168
168
  - spec/unit/configuration_spec.rb
169
+ - spec/unit/formatter_spec.rb
170
+ - spec/unit/spec_helper.rb
169
171
  homepage: https://github.com/mrackwitz/CLIntegracon
170
172
  licenses:
171
173
  - MIT
@@ -210,3 +212,5 @@ test_files:
210
212
  - spec/integration/coffeemaker_sweetner_honey/before/Coffeemakerfile.yml
211
213
  - spec/unit/adapter/bacon_spec.rb
212
214
  - spec/unit/configuration_spec.rb
215
+ - spec/unit/formatter_spec.rb
216
+ - spec/unit/spec_helper.rb