xcpretty 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1a03b19be84f708774b6c76d7b89cac3231eed1
4
- data.tar.gz: 282c28b193dd9f9e92e83e46f38e86481c3f8432
3
+ metadata.gz: cc82776a1b5b7af57ec1112e3272f12a6942513b
4
+ data.tar.gz: 521c086a0311bf369acd88e7edf6ca3730ae6389
5
5
  SHA512:
6
- metadata.gz: 9ac22b284e55a4397cb190a9406e4fc4992ab79ebb2b1a25b1210361f5bacbebdd26e269228ccdbb2cd3856bea055314c66f52f78bf213ae2c34d0110aa21230
7
- data.tar.gz: 63fb8efd9849d07ad752efad960bfdadab4a67e4d741600fe62a70a92f3e97b4e3b5bf725b7ad2d06ebb85612dcd155dae8eef4d77c961b5f14b494b66de4116
6
+ metadata.gz: c9e3c17930e218fea3f34d5d8ea42b279d269c3869616c039ce84f356bdb9ac9528a3800d1fc25fcba975776036edc3ef0fb27894d0edbf0ea9a415603865d5a
7
+ data.tar.gz: 6d1274dbbf1824d65e07cf802d4f5795276e850778e24c2f82d07a47fb822d37761eebba5b2286a71ddcfae6c8b46f058160077bc96211c1c3a1dd3c65028af6
data/lib/xcpretty.rb CHANGED
@@ -1,14 +1,15 @@
1
- require "xcpretty/version"
2
- require "xcpretty/printer"
3
- require "xcpretty/syntax"
4
- require "xcpretty/formatters/formatter"
5
- require "xcpretty/formatters/simple"
6
- require "xcpretty/formatters/rspec"
7
- require "xcpretty/formatters/knock"
8
- require "xcpretty/formatters/tap"
9
- require "xcpretty/reporters/junit"
10
- require "xcpretty/reporters/html"
11
- require "xcpretty/reporters/json_compilation_database"
1
+ require 'xcpretty/version'
2
+ require 'xcpretty/printer'
3
+ require 'xcpretty/syntax'
4
+ require 'xcpretty/snippet'
5
+ require 'xcpretty/formatters/formatter'
6
+ require 'xcpretty/formatters/simple'
7
+ require 'xcpretty/formatters/rspec'
8
+ require 'xcpretty/formatters/knock'
9
+ require 'xcpretty/formatters/tap'
10
+ require 'xcpretty/reporters/junit'
11
+ require 'xcpretty/reporters/html'
12
+ require 'xcpretty/reporters/json_compilation_database'
12
13
 
13
14
  module XCPretty
14
15
 
@@ -111,14 +111,21 @@ module XCPretty
111
111
 
112
112
  def format_failures(failures_per_suite)
113
113
  failures_per_suite.map do |suite, failures|
114
- formatted_failures = failures.map do |f|
115
- " #{f[:test_case]}, #{red(f[:reason])}\n #{cyan(f[:file])}"
114
+ formatted_failures = failures.map do |failure|
115
+ format_failure(failure)
116
116
  end.join("\n\n")
117
117
 
118
118
  "\n#{suite}\n#{formatted_failures}"
119
119
  end.join("\n")
120
120
  end
121
121
 
122
+ def format_failure(f)
123
+ " #{f[:test_case]}, #{red(f[:reason])}\n #{cyan(f[:file_path])}\n" +
124
+ " ```\n" +
125
+ Syntax.highlight(Snippet.from_filepath(f[:file_path])) +
126
+ " ```"
127
+ end
128
+
122
129
  def error_symbol
123
130
  use_unicode? ? ERROR : ASCII_ERROR
124
131
  end
@@ -391,7 +391,7 @@ module XCPretty
391
391
  def store_failure(file, test_suite, test_case, reason)
392
392
  failures_per_suite[test_suite] ||= []
393
393
  failures_per_suite[test_suite] << {
394
- :file => file,
394
+ :file_path => file,
395
395
  :reason => reason,
396
396
  :test_case => test_case
397
397
  }
@@ -43,17 +43,12 @@ module XCPretty
43
43
 
44
44
  private
45
45
 
46
- def formatted_snippet filepath
47
- file, line = filepath.split(':')
48
- f = File.open(file)
49
- line.to_i.times { f.gets }
50
- text = $_.strip
51
- f.close
52
- Syntax.highlight(text, "-f html -O style=colorful -O noclasses")
53
- rescue
54
- nil
46
+ def formatted_snippet(filepath)
47
+ snippet = Snippet.from_filepath(filepath)
48
+ Syntax.highlight(snippet, "-f html -O style=colorful -O noclasses")
55
49
  end
56
50
 
51
+
57
52
  def add_test(suite_name, data)
58
53
  @test_count += 1
59
54
  @test_suites[suite_name] ||= {:tests => []}
@@ -66,6 +61,7 @@ module XCPretty
66
61
 
67
62
  def write_report
68
63
  File.open(@filepath, 'w') do |f|
64
+ # WAT: get rid of these locals. BTW Cucumber fails if you remove them
69
65
  test_suites = @test_suites
70
66
  fail_count = @fail_count
71
67
  test_count = @test_count
@@ -74,4 +70,4 @@ module XCPretty
74
70
  end
75
71
  end
76
72
  end
77
- end
73
+ end
@@ -0,0 +1,34 @@
1
+ module XCPretty
2
+ class Snippet
3
+
4
+ def self.from_filepath(filepath)
5
+ path, line = filepath.split(':')
6
+ file = File.open(path)
7
+
8
+ text = read_snippet(file, line)
9
+
10
+ file.close
11
+ text
12
+ rescue
13
+ ''
14
+ end
15
+
16
+
17
+ private
18
+
19
+ def self.read_snippet(file, around_line)
20
+ text = ""
21
+ starting_position = around_line.to_i - 2
22
+ starting_position.times { file.gets }
23
+ 3.times { text += readline(file) }
24
+ text
25
+ end
26
+
27
+ def self.readline(file)
28
+ file.gets
29
+ $_ || ''
30
+ end
31
+
32
+ end
33
+ end
34
+
@@ -18,4 +18,3 @@ module XCPretty
18
18
  end
19
19
  end
20
20
  end
21
-
@@ -1,3 +1,3 @@
1
1
  module XCPretty
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,64 @@
1
+ //
2
+ // NSStringTests.m
3
+ // SampleProject
4
+ //
5
+ // Created by Neil on 05/12/2012.
6
+ // Copyright (c) 2012 @mneorr | mneorr.com. All rights reserved.
7
+ //
8
+
9
+ #import "Kiwi.h"
10
+ #import "ObjectiveSugar.h"
11
+
12
+ SPEC_BEGIN(StringAdditions)
13
+
14
+ describe(@"Foundation-style functions", ^{
15
+
16
+ it(@"NSStringWithFormat makes NSString -stringWithFormat", ^{
17
+
18
+ [[NSStringWithFormat(@"This is %@", @1) should] equal:@"This is 1"];
19
+ });
20
+
21
+ });
22
+
23
+ describe(@"Additions", ^{
24
+
25
+ NSString *sentence = @"Jane Doe's going in a shop,and,yeah;";
26
+
27
+ it(@"-split splits by whitespace", ^{
28
+ [[[@" the\r\nquick brown\t \tfox\n" split] should] equal:@[@"the", @"quick", @"brown", @"fox"]];
29
+ });
30
+
31
+ it(@"-split: splits with given delimiter", ^{
32
+ [[[sentence split:@","] should] equal:@[@"Jane Doe's going in a shop", @"and", @"yeah;"]];
33
+ });
34
+
35
+ it(@"-split: splits with delimiter string, not just a char", ^{
36
+ [[[@"one / two / three" split:@" / "] should] equal:@[@"one", @"two", @"three"]];
37
+ });
38
+
39
+ it(@"contains string", ^{
40
+ [[@([sentence containsString:@"jane doe"]) should] beTrue];
41
+ });
42
+
43
+ context(@"CamelCase and snake_case", ^{
44
+
45
+ it(@"converts snake_cased to CamelCased", ^{
46
+ [[[@"snake_case" camelCase] should] equal:@"SnakeCase"];
47
+ });
48
+
49
+ it(@"handles correctly snake case on beginning and at the end", ^{
50
+ [[[@"_snake_case" camelCase] should] equal:@"SnakeCase"];
51
+ [[[@"snake_case_" camelCase] should] equal:@"SnakeCase"];
52
+ });
53
+
54
+ });
55
+
56
+ it(@"-strip strips whitespaces and newlines from both ends", ^{
57
+ [[[@" Look mo, no empties! " strip] should] equal:@"Look mo, no empties!"];
58
+ });
59
+
60
+ });
61
+
62
+
63
+
64
+ SPEC_END
@@ -0,0 +1 @@
1
+ [[[@1 should] equal] @3];
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'xcpretty'
4
+ require 'fixtures/constants'
4
5
 
5
6
  module XCPretty
6
7
 
@@ -64,16 +65,21 @@ module XCPretty
64
65
 
65
66
  if RUBY_VERSION > '1.8.7'
66
67
  it "formats failures per suite" do
68
+ Syntax.stub(:highlight) { |text| text }
69
+
70
+ first_path = File.expand_path('spec/fixtures/NSStringTests.m:46')
71
+ second_path = File.expand_path('spec/fixtures/NSStringTests.m:57')
72
+
67
73
  failures = {
68
74
  'CarSpec' => [
69
75
  {
70
- :file => 'path/to/file2',
76
+ :file_path => first_path,
71
77
  :reason => "just doesn't work",
72
78
  :test_case => 'Starting the car'
73
79
  }],
74
80
  'StringSpec' => [
75
81
  {
76
- :file => 'path/to/file1',
82
+ :file_path => second_path,
77
83
  :reason => "doesn't split",
78
84
  :test_case => 'Splitting the string'
79
85
  }]
@@ -82,15 +88,24 @@ module XCPretty
82
88
 
83
89
  CarSpec
84
90
  Starting the car, #{@formatter.red("just doesn't work")}
85
- #{@formatter.cyan("path/to/file2")}
91
+ #{@formatter.cyan(first_path)}
92
+ ```
93
+ it(@"converts snake_cased to CamelCased", ^{
94
+ [[[@"snake_case" camelCase] should] equal:@"SnakeCase"];
95
+ });
96
+ ```
86
97
 
87
98
  StringSpec
88
99
  Splitting the string, #{@formatter.red("doesn't split")}
89
- #{@formatter.cyan("path/to/file1")}
100
+ #{@formatter.cyan(second_path)}
101
+ ```
102
+ it(@"-strip strips whitespaces and newlines from both ends", ^{
103
+ [[[@" Look mo, no empties! " strip] should] equal:@"Look mo, no empties!"];
104
+ });
105
+ ```
90
106
 
91
107
 
92
108
  #{@formatter.red(SAMPLE_EXECUTED_TESTS)})
93
-
94
109
  end
95
110
  end # only ruby 1.9 above because of ordered hashes
96
111
 
@@ -0,0 +1,39 @@
1
+ require 'xcpretty/snippet'
2
+
3
+ module XCPretty
4
+
5
+ describe Snippet do
6
+
7
+ it "gets the snippet out of the file path" do
8
+ path = File.expand_path('spec/fixtures/NSStringTests.m:36')
9
+ Snippet.from_filepath(path).should ==
10
+ <<-EOS
11
+ it(@"-split: splits with delimiter string, not just a char", ^{
12
+ [[[@"one / two / three" split:@" / "] should] equal:@[@"one", @"two", @"three"]];
13
+ });
14
+ EOS
15
+ end
16
+
17
+ it "doesn't crash when there's nothing to read" do
18
+ path = File.expand_path('spec/fixtures/NSStringTests.m:64')
19
+ Snippet.from_filepath(path).should == "\nSPEC_END\n"
20
+ end
21
+
22
+ it "doesn't crash if file path is invalid" do
23
+ path = 'invalid-path'
24
+ Snippet.from_filepath(path).should == ''
25
+ end
26
+
27
+ it "doesn't crash if a failure is on the first line" do
28
+ path = File.expand_path('spec/fixtures/NSStringTests.m:0')
29
+ Snippet.from_filepath(path).should == "//\n// NSStringTests.m\n// SampleProject\n"
30
+ end
31
+
32
+ it "doesn't crash if the file has only 1 line" do
33
+ path = File.expand_path('spec/fixtures/oneliner.m:0')
34
+ Snippet.from_filepath(path).should == "[[[@1 should] equal] @3];\n"
35
+ end
36
+
37
+ end
38
+ end
39
+
data/xcpretty.gemspec CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.3"
30
30
  spec.add_development_dependency "rake"
31
- spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "rspec", "~> 2"
32
32
  spec.add_development_dependency "cucumber"
33
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcpretty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marin Usalj
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-09 00:00:00.000000000 Z
12
+ date: 2014-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,16 +43,16 @@ dependencies:
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '2'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '2'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: cucumber
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -118,10 +118,13 @@ files:
118
118
  - lib/xcpretty/reporters/html.rb
119
119
  - lib/xcpretty/reporters/json_compilation_database.rb
120
120
  - lib/xcpretty/reporters/junit.rb
121
+ - lib/xcpretty/snippet.rb
121
122
  - lib/xcpretty/syntax.rb
122
123
  - lib/xcpretty/version.rb
124
+ - spec/fixtures/NSStringTests.m
123
125
  - spec/fixtures/constants.rb
124
126
  - spec/fixtures/custom_formatter.rb
127
+ - spec/fixtures/oneliner.m
125
128
  - spec/fixtures/raw_kiwi_compilation_fail.txt
126
129
  - spec/fixtures/raw_kiwi_fail.txt
127
130
  - spec/fixtures/raw_specta_fail.txt
@@ -133,6 +136,7 @@ files:
133
136
  - spec/xcpretty/formatters/simple_spec.rb
134
137
  - spec/xcpretty/parser_spec.rb
135
138
  - spec/xcpretty/printer_spec.rb
139
+ - spec/xcpretty/snippet_spec.rb
136
140
  - spec/xcpretty/syntax_spec.rb
137
141
  - vendor/json_pure/COPYING
138
142
  - vendor/json_pure/LICENSE
@@ -181,8 +185,10 @@ test_files:
181
185
  - features/tap_format.feature
182
186
  - features/test_format.feature
183
187
  - features/xcpretty.feature
188
+ - spec/fixtures/NSStringTests.m
184
189
  - spec/fixtures/constants.rb
185
190
  - spec/fixtures/custom_formatter.rb
191
+ - spec/fixtures/oneliner.m
186
192
  - spec/fixtures/raw_kiwi_compilation_fail.txt
187
193
  - spec/fixtures/raw_kiwi_fail.txt
188
194
  - spec/fixtures/raw_specta_fail.txt
@@ -194,5 +200,6 @@ test_files:
194
200
  - spec/xcpretty/formatters/simple_spec.rb
195
201
  - spec/xcpretty/parser_spec.rb
196
202
  - spec/xcpretty/printer_spec.rb
203
+ - spec/xcpretty/snippet_spec.rb
197
204
  - spec/xcpretty/syntax_spec.rb
198
205
  has_rdoc: