wrong 0.6.3-java → 0.7.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.markdown +10 -7
  2. data/lib/wrong.rb +1 -0
  3. data/lib/wrong/adapters/rspec.rb +4 -0
  4. data/lib/wrong/assert.rb +1 -2
  5. data/lib/wrong/chunk.rb +5 -170
  6. data/lib/wrong/close_to.rb +7 -1
  7. data/lib/wrong/config.rb +3 -3
  8. data/lib/wrong/d.rb +2 -1
  9. data/lib/wrong/failure_message.rb +109 -7
  10. data/lib/wrong/message/string_comparison.rb +1 -1
  11. data/lib/wrong/sexp_ext.rb +2 -1
  12. data/lib/wrong/terminal.rb +43 -0
  13. data/lib/wrong/version.rb +1 -1
  14. data/test/adapters/railsapp/app/controllers/application_controller.rb +3 -0
  15. data/test/adapters/railsapp/app/helpers/application_helper.rb +2 -0
  16. data/test/adapters/railsapp/config/application.rb +54 -0
  17. data/test/adapters/railsapp/config/boot.rb +6 -0
  18. data/test/adapters/railsapp/config/environment.rb +5 -0
  19. data/test/adapters/railsapp/config/environments/development.rb +30 -0
  20. data/test/adapters/railsapp/config/environments/production.rb +60 -0
  21. data/test/adapters/railsapp/config/environments/test.rb +42 -0
  22. data/test/adapters/railsapp/config/initializers/backtrace_silencers.rb +7 -0
  23. data/test/adapters/railsapp/config/initializers/inflections.rb +10 -0
  24. data/test/adapters/railsapp/config/initializers/mime_types.rb +5 -0
  25. data/test/adapters/railsapp/config/initializers/secret_token.rb +7 -0
  26. data/test/adapters/railsapp/config/initializers/session_store.rb +8 -0
  27. data/test/adapters/railsapp/config/initializers/wrap_parameters.rb +14 -0
  28. data/test/adapters/railsapp/config/routes.rb +58 -0
  29. data/test/adapters/railsapp/db/seeds.rb +7 -0
  30. data/test/adapters/railsapp/spec/spec_helper.rb +33 -0
  31. data/test/adapters/railsapp/spec/wrong_spec.rb +8 -0
  32. data/test/adapters/rspec_rails_test.rb +4 -4
  33. data/test/adapters/rspec_test.rb +2 -2
  34. data/test/assert_advanced_test.rb +9 -1
  35. data/test/chunk_test.rb +0 -200
  36. data/test/close_to_test.rb +34 -2
  37. data/test/d_test.rb +2 -2
  38. data/test/eventually_test.rb +27 -34
  39. data/test/failure_message_test.rb +212 -13
  40. data/test/test_helper.rb +2 -2
  41. metadata +47 -8
  42. data/lib/wrong/ruby2ruby_patch.rb +0 -37
@@ -1,5 +1,6 @@
1
1
  require "./test/test_helper"
2
2
  require "wrong/assert"
3
+ require "wrong/chunk"
3
4
  require "wrong/failure_message"
4
5
 
5
6
  class BogusFormatter < Wrong::FailureMessage::Formatter
@@ -15,6 +16,11 @@ end
15
16
  class BogusPredicate < Predicated::Predicate
16
17
  end
17
18
 
19
+ # normalize yaml
20
+ def y(s)
21
+ s.gsub(/--- $/, "---").chomp
22
+ end
23
+
18
24
  module Wrong
19
25
 
20
26
  describe Wrong::FailureMessage::Formatter do
@@ -27,13 +33,13 @@ module Wrong
27
33
  end
28
34
  end
29
35
 
30
- describe Wrong::FailureMessage do
36
+ describe Wrong::FailureMessage do
31
37
  include Wrong::Assert
32
38
 
33
39
  it "can register a formatter class for a predicate pattern" do
34
40
  Wrong::FailureMessage.register_formatter(::BogusFormatter)
35
41
  assert { Wrong::FailureMessage.formatter_for(::BogusPredicate.new).is_a? ::BogusFormatter }
36
- assert { Wrong::FailureMessage.formatters.include?(::BogusFormatter)}
42
+ assert { Wrong::FailureMessage.formatters.include?(::BogusFormatter) }
37
43
  end
38
44
 
39
45
  before do
@@ -43,22 +49,21 @@ module Wrong
43
49
  end
44
50
 
45
51
  def message(options = {}, &block)
46
- valence = options[:valence] || :assert
52
+ valence = options[:valence] || :assert
47
53
  explanation = options[:explanation]
48
54
  Wrong::FailureMessage.new(@chunk, valence, explanation)
49
55
  end
50
56
 
51
-
52
- describe "#basic" do
57
+ describe "#basic" do
53
58
  it "shows the code" do
54
59
  assert { message.basic == "Expected ((2 + 2) == 5)" }
55
60
  end
56
-
61
+
57
62
  it "reverses the message for :deny valence" do
58
63
  assert { message(:valence => :deny).basic == "Didn't expect ((2 + 2) == 5)" }
59
64
  end
60
65
  end
61
-
66
+
62
67
  describe '#full' do
63
68
  it "contains the basic message" do
64
69
  assert { message.full.include? message.basic }
@@ -68,23 +73,217 @@ module Wrong
68
73
  msg = message(:explanation => "the sky is falling")
69
74
  assert { msg.full.include? "the sky is falling" }
70
75
  end
71
-
76
+
72
77
  it "doesn't say 'but' if there are no details" do
73
78
  @chunk = Wrong::Chunk.new(__FILE__, __LINE__ + 1) do
74
79
  2
75
80
  end
76
- assert { @chunk.details.empty? }
77
- deny { message.full.include? ", but"}
81
+ assert { message.details.empty? }
82
+ deny { message.full.include? ", but" }
78
83
  end
79
-
84
+
80
85
  it "says 'but' if there are details" do
81
86
  @chunk = Wrong::Chunk.new(__FILE__, __LINE__ + 1) do
82
87
  2 + 2 == 5
83
88
  end
84
- assert { message.full.include? ", but\n (2 + 2) is 4"}
89
+ assert { message.full.include? ", but\n (2 + 2) is 4" }
85
90
  end
86
-
87
91
  end
88
92
 
93
+ describe "#details" do
94
+ def details(&block)
95
+ @chunk = Wrong::Chunk.from_block(block, 1)
96
+ message.details
97
+ end
98
+
99
+ it "returns an empty string if there are no parts" do
100
+ d = details { assert { true } }
101
+ assert d == ""
102
+ end
103
+
104
+ it "returns an string beginning with a newline if there are parts" do
105
+ x = 10
106
+ d = details { assert { x == 10 } }
107
+ assert d == "\n x is 10\n"
108
+ end
109
+
110
+ it "skips literals" do
111
+ d = details { assert { 10 == 11 } }
112
+ assert d == ""
113
+ end
114
+
115
+ it "shows lots of details" do
116
+ x = 10
117
+ d = details { assert { (x * (x - 10)) == (x / (x + 10)) } }
118
+ assert d == <<-DETAILS
119
+
120
+ (x * (x - 10)) is 0
121
+ x is 10
122
+ (x - 10) is 0
123
+ (x / (x + 10)) is 0
124
+ (x + 10) is 20
125
+ DETAILS
126
+ end
127
+
128
+ it "skips duplicates" do
129
+ x = 10
130
+ d = details { assert { (x + 5) == 1 + (x + 5) } }
131
+ assert d == <<-DETAILS
132
+
133
+ (x + 5) is 15
134
+ x is 10
135
+ (1 + (x + 5)) is 16
136
+ DETAILS
137
+ end
138
+
139
+ it "shows exceptions" do
140
+ d = details { assert { (raise "hi") == 1 } }
141
+ assert d == "\n raise(\"hi\") raises RuntimeError: hi\n"
142
+ end
143
+
144
+ it "indents newlines inside the exception message" do
145
+ d = details { assert { (raise "hello\nsailor") == 1 } }
146
+ assert d == "\n raise(\"hello\\nsailor\") raises RuntimeError: hello\n sailor\n"
147
+ end
148
+
149
+ it "abridges exceptions with no message" do
150
+ d = details { assert { (raise Exception.new) == 1 } }
151
+ assert d == "\n raise(Exception.new) raises Exception\n" +
152
+ " Exception.new is #<Exception: Exception>\n"
153
+ end
154
+
155
+ it "inspects values" do
156
+ x = "flavor:\tvanilla"
157
+ d = details { assert { x == "flavor:\tchocolate" } }
158
+ # this means it's a literal slash plus t inside double quotes -- i.e. it shows the escaped (inspected) string
159
+ assert d == "\n" + ' x is "flavor:\tvanilla"' + "\n"
160
+ end
161
+
162
+ it "splits lower-down details correctly (bug)" do
163
+ hash = {:flavor => "vanilla"}
164
+ exception_with_newlines = Exception.new(hash.to_yaml.chomp)
165
+ d = details {
166
+ rescuing { raise exception_with_newlines }.message.include?(":flavor: chocolate")
167
+ }
168
+ assert (y(d).include? "exception_with_newlines is #<Exception: ---\n :flavor: vanilla>"), d.inspect
169
+ end
170
+
171
+ it "skips assignments" do
172
+ y = 14
173
+ d = details do
174
+ x = 7; y
175
+ end
176
+ assert d !~ /x = 7/
177
+ assert d =~ /y is 14/
178
+ end
179
+
180
+ class Weirdo
181
+ def initialize(inspected_value)
182
+ @inspected_value = inspected_value
183
+ end
184
+
185
+ def inspect
186
+ @inspected_value
187
+ end
188
+ end
189
+
190
+ it "indents unescaped newlines inside the inspected value" do
191
+ x = Weirdo.new("first\nsecond\nthird")
192
+ d = details { assert { x == "foo" } }
193
+ assert d == "\n x is first\n second\n third\n"
194
+ end
195
+
196
+ describe '#pretty_value' do
197
+ before do
198
+ @chunk = chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
199
+ true
200
+ CODE
201
+ end
202
+
203
+ after do
204
+ Wrong::Terminal.width = 80
205
+ end
206
+
207
+ it 'inspects its value' do
208
+ assert message.pretty_value(12) == "12"
209
+ assert message.pretty_value("foo") == "\"foo\""
210
+ end
211
+
212
+ it 'escapes newlines in strings' do
213
+ assert message.pretty_value("foo\nbar\nbaz") == "\"foo\\nbar\\nbaz\""
214
+ end
215
+
216
+ it 'indents newlines in raw inspect values (e.g. exceptions or YAML or whatever)' do
217
+ w = Weirdo.new("foo\nbar\nbaz")
218
+ assert message.pretty_value(w) == "foo\n bar\n baz"
219
+ end
220
+
221
+ it "returns the terminal width" do
222
+ assert Terminal.width.is_a? Fixnum
223
+ assert Terminal.width > 0
224
+ end
225
+
226
+ it "can fake the terminal width" do
227
+ Terminal.width = 66
228
+ assert Terminal.width == 66
229
+ end
230
+
231
+ # def pretty_value(value, starting_col = 0, indent_wrapped_lines = 3, size = Terminal.size)
232
+
233
+ it 'inserts newlines in really long values, wrapped at the given width' do
234
+ abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
235
+ pretty = message.pretty_value(abc, 0, 0, 10)
236
+ assert pretty == <<-DONE.chomp
237
+ abcdefghij
238
+ klmnopqrst
239
+ uvwxyz
240
+ DONE
241
+ end
242
+
243
+ it 'inserts newlines in really long values, wrapped at the terminal width' do
244
+ Terminal.width = 10
245
+ abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
246
+ pretty = message.pretty_value(abc, 0, 0)
247
+ assert pretty == <<-DONE.chomp
248
+ abcdefghij
249
+ klmnopqrst
250
+ uvwxyz
251
+ DONE
252
+ end
253
+
254
+ it 'subtracts the starting column from the wrapped width of the first line' do
255
+ abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
256
+ pretty = message.pretty_value(abc, 2, 0, 10)
257
+ assert pretty == <<-DONE.chomp
258
+ abcdefgh
259
+ ijklmnopqr
260
+ stuvwxyz
261
+ DONE
262
+ end
263
+
264
+ it "indents wrapped lines" do
265
+ abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
266
+ pretty = message.pretty_value(abc, 2, 3, 10)
267
+ assert pretty == <<-DONE.chomp
268
+ abcdefgh
269
+ ijklmno
270
+ pqrstuv
271
+ wxyz
272
+ DONE
273
+ end
274
+
275
+ it "wraps correctly" do
276
+ hash = {:flavor => "vanilla"}
277
+ object = Weirdo.new(hash.to_yaml.chomp)
278
+ pretty = message.pretty_value(object, 2, 3, 80)
279
+ assert y(pretty) == y(<<-DONE), pretty.inspect
280
+ ---
281
+ :flavor: vanilla
282
+ DONE
283
+ end
284
+
285
+
286
+ end
287
+ end
89
288
  end
90
289
  end
data/test/test_helper.rb CHANGED
@@ -37,8 +37,8 @@ def sys(cmd, expected_status = 0)
37
37
  # in Ruby 1.8, wait_thread is nil :-( so just pretend the process was successful (status 0)
38
38
  exit_status = (wait_thread.value.exitstatus if wait_thread) || 0
39
39
  output = stdout.read + stderr.read
40
- unless expected_status.nil?
41
- assert(cmd) { output and exit_status == expected_status }
40
+ unless expected_status == :ignore
41
+ assert(cmd) { cmd and output and exit_status == expected_status }
42
42
  end
43
43
  yield output if block_given?
44
44
  output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrong
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: java
7
7
  authors:
@@ -10,24 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-14 00:00:00.000000000 Z
13
+ date: 2012-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: predicated
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ! '>='
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.2.3
22
+ version: 0.2.6
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ! '>='
28
+ - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 0.2.3
30
+ version: 0.2.6
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: ruby_parser
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -131,12 +131,30 @@ files:
131
131
  - lib/wrong/message/test_context.rb
132
132
  - lib/wrong/rainbow.rb
133
133
  - lib/wrong/rescuing.rb
134
- - lib/wrong/ruby2ruby_patch.rb
135
134
  - lib/wrong/sexp_ext.rb
135
+ - lib/wrong/terminal.rb
136
136
  - lib/wrong/version.rb
137
137
  - lib/wrong.rb
138
138
  - README.markdown
139
139
  - test/adapters/minitest_test.rb
140
+ - test/adapters/railsapp/app/controllers/application_controller.rb
141
+ - test/adapters/railsapp/app/helpers/application_helper.rb
142
+ - test/adapters/railsapp/config/application.rb
143
+ - test/adapters/railsapp/config/boot.rb
144
+ - test/adapters/railsapp/config/environment.rb
145
+ - test/adapters/railsapp/config/environments/development.rb
146
+ - test/adapters/railsapp/config/environments/production.rb
147
+ - test/adapters/railsapp/config/environments/test.rb
148
+ - test/adapters/railsapp/config/initializers/backtrace_silencers.rb
149
+ - test/adapters/railsapp/config/initializers/inflections.rb
150
+ - test/adapters/railsapp/config/initializers/mime_types.rb
151
+ - test/adapters/railsapp/config/initializers/secret_token.rb
152
+ - test/adapters/railsapp/config/initializers/session_store.rb
153
+ - test/adapters/railsapp/config/initializers/wrap_parameters.rb
154
+ - test/adapters/railsapp/config/routes.rb
155
+ - test/adapters/railsapp/db/seeds.rb
156
+ - test/adapters/railsapp/spec/spec_helper.rb
157
+ - test/adapters/railsapp/spec/wrong_spec.rb
140
158
  - test/adapters/rspec1/failing_spec.rb
141
159
  - test/adapters/rspec2/failing_spec.rb
142
160
  - test/adapters/rspec_rails_test.rb
@@ -176,13 +194,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
194
  version: '0'
177
195
  segments:
178
196
  - 0
179
- hash: 2653256029812860538
197
+ hash: -3959887704133047026
180
198
  required_rubygems_version: !ruby/object:Gem::Requirement
181
199
  none: false
182
200
  requirements:
183
201
  - - ! '>='
184
202
  - !ruby/object:Gem::Version
185
203
  version: '0'
204
+ segments:
205
+ - 0
206
+ hash: -3959887704133047026
186
207
  requirements: []
187
208
  rubyforge_project: wrong
188
209
  rubygems_version: 1.8.24
@@ -192,6 +213,24 @@ summary: Wrong provides a general assert method that takes a predicate block. A
192
213
  failure messages are rich in detail.
193
214
  test_files:
194
215
  - test/adapters/minitest_test.rb
216
+ - test/adapters/railsapp/app/controllers/application_controller.rb
217
+ - test/adapters/railsapp/app/helpers/application_helper.rb
218
+ - test/adapters/railsapp/config/application.rb
219
+ - test/adapters/railsapp/config/boot.rb
220
+ - test/adapters/railsapp/config/environment.rb
221
+ - test/adapters/railsapp/config/environments/development.rb
222
+ - test/adapters/railsapp/config/environments/production.rb
223
+ - test/adapters/railsapp/config/environments/test.rb
224
+ - test/adapters/railsapp/config/initializers/backtrace_silencers.rb
225
+ - test/adapters/railsapp/config/initializers/inflections.rb
226
+ - test/adapters/railsapp/config/initializers/mime_types.rb
227
+ - test/adapters/railsapp/config/initializers/secret_token.rb
228
+ - test/adapters/railsapp/config/initializers/session_store.rb
229
+ - test/adapters/railsapp/config/initializers/wrap_parameters.rb
230
+ - test/adapters/railsapp/config/routes.rb
231
+ - test/adapters/railsapp/db/seeds.rb
232
+ - test/adapters/railsapp/spec/spec_helper.rb
233
+ - test/adapters/railsapp/spec/wrong_spec.rb
195
234
  - test/adapters/rspec1/failing_spec.rb
196
235
  - test/adapters/rspec2/failing_spec.rb
197
236
  - test/adapters/rspec_rails_test.rb
@@ -1,37 +0,0 @@
1
- class ::Ruby2Ruby < ::SexpProcessor
2
- # see http://gist.github.com/321038
3
- # Monkey-patch to have Ruby2Ruby#translate with r2r >= 1.2.3, from
4
- # http://seattlerb.rubyforge.org/svn/ruby2ruby/1.2.2/lib/ruby2ruby.rb
5
- def self.translate(klass_or_str, method = nil)
6
- sexp = ParseTree.translate(klass_or_str, method)
7
- unifier = Unifier.new
8
- unifier.processors.each do |p|
9
- p.unsupported.delete :cfunc # HACK
10
- end
11
- sexp = unifier.process(sexp)
12
- self.new.process(sexp)
13
- end
14
-
15
- #sconover - 7/2010 - monkey-patch
16
- #{1=>2}=={1=>2}
17
- #The right side was having its braces cut off because of
18
- #special handling of hashes within arglists within the seattlerb code.
19
- #I tried to fork r2r and add a test, but a lot of other tests
20
- #broke, and I just dont understand the test in ruby2ruby.
21
- #So I'm emailing the author...
22
- def process_hash(exp)
23
- result = []
24
- until exp.empty?
25
- lhs = process(exp.shift)
26
- rhs = exp.shift
27
- t = rhs.first
28
- rhs = process rhs
29
- rhs = "(#{rhs})" unless [:lit, :str].include? t # TODO: verify better!
30
-
31
- result << "#{lhs} => #{rhs}"
32
- end
33
-
34
- return "{ #{result.join(', ')} }"
35
- end
36
-
37
- end