rspec-by 0.0.6 → 0.0.7

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.
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.3.0
5
+
6
+ install:
7
+ - bundle install
8
+
9
+ script:
10
+ - bundle exec rspec
@@ -42,12 +42,14 @@ module RSpec::Core
42
42
 
43
43
  class Example
44
44
  private
45
-
45
+
46
46
  alias :start_without_reporter :start
47
47
 
48
48
  def start(reporter)
49
49
  start_without_reporter(reporter)
50
- @example_group_instance.instance_variable_set(:@by_reporter, reporter)
50
+ if @example_group_instance
51
+ @example_group_instance.instance_variable_set(:@by_reporter, reporter)
52
+ end
51
53
  end
52
54
  end
53
55
  end
@@ -9,9 +9,11 @@ module RSpec
9
9
  module By
10
10
  class Formatter < RSpec::Core::Formatters::DocumentationFormatter
11
11
  RSpec::Core::Formatters.register self,
12
- :example_failed,
12
+ :example_group_started,
13
+ :example_group_finished,
13
14
  :example_started,
14
15
  :example_passed,
16
+ :example_failed,
15
17
  :by_started,
16
18
  :by_ended
17
19
 
@@ -20,76 +22,111 @@ module RSpec
20
22
  def initialize(output)
21
23
  super(output)
22
24
  @failed_examples = []
23
- @by_message_length = 0
25
+ @bullets = [Bullet.new('', true)]
26
+ end
27
+
28
+ def example_group_started(notification)
29
+ bullet_start(notification.group.description)
30
+ end
31
+
32
+ def example_group_finished(_notification)
33
+ @bullets.pop
24
34
  end
25
35
 
26
36
  def example_started(notification)
27
- output.puts(
28
- "#{current_indentation}Example: #{notification.example.description}")
29
- @group_level += 1
30
- @example_began = @during = RSpec::Core::Time.now
37
+ bullet_start(notification.example.description)
31
38
  end
32
39
 
33
40
  def example_passed(passed)
34
- @group_level -= 1
35
- passed_msg = indent("Passed")
36
- end_msg = end_tm.rjust(RIGHT_MARGIN - passed_msg.length, ' ')
37
- output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
38
- "#{passed_msg}#{end_msg}", :success)
41
+ bullet_end(:success)
39
42
  end
40
43
 
41
44
  def example_failed(failure)
42
- @group_level -= 1
43
- output.puts("#{current_indentation}Failed in #{end_tm}")
44
45
  @failed_examples << failure.example
45
46
  output.puts failure.fully_formatted(@failed_examples.size)
46
- output.puts
47
+ bullet_end
47
48
  end
48
49
 
49
50
  def by_started message
50
- res = indent message
51
- @by_message_length = res.length
52
- output.print by_output(res)
51
+ bullet_start(message, :cyan)
53
52
  end
54
53
 
55
54
  def by_ended(message)
56
- message += during_tm
57
- output.puts by_output(message.rjust(RIGHT_MARGIN - @by_message_length, ' '))
55
+ bullet_end(:cyan)
58
56
  end
59
57
 
60
58
  def indent message
61
59
  "#{current_indentation}#{message}"
62
60
  end
63
61
 
64
- def by_output message
65
- RSpec::Core::Formatters::ConsoleCodes.wrap(message, :cyan)
62
+ def current_indentation
63
+ ' ' * (@bullets.size - 1)
66
64
  end
67
65
 
68
- def during_tm
69
- temp = RSpec::Core::Time.now
70
- delta = temp - @during
71
- @during = temp
72
- format_time(delta)
66
+ def current_bullet
67
+ @bullets.last
73
68
  end
74
69
 
75
- def end_tm
76
- delta = RSpec::Core::Time.now - @example_began
77
- format_time(delta)
70
+ def bullet_start(message, color = :white)
71
+ unless current_bullet.nested?
72
+ offset = RIGHT_MARGIN - current_bullet.offset
73
+ output.print RSpec::Core::Formatters::ConsoleCodes.wrap(current_bullet.delta_t.rjust(offset, ' '), color)
74
+ output.puts ''
75
+ current_bullet.nest
76
+ end
77
+ res = indent message
78
+ output.print RSpec::Core::Formatters::ConsoleCodes.wrap(res, color)
79
+ @bullets.push(Bullet.new(res))
78
80
  end
79
81
 
80
- def format_time(duration)
81
- if duration > 60
82
- minutes = duration.to_i / 60
83
- seconds = duration - minutes * 60
84
- "#{minutes}m #{format_seconds(seconds)}s"
85
- else
86
- "#{format_seconds(duration)}s"
82
+ def bullet_end(color = :white)
83
+ bullet = @bullets.pop
84
+ if bullet.nested?
85
+ bullet.message = ''
87
86
  end
87
+ offset = RIGHT_MARGIN - bullet.offset
88
+ output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(bullet.delta_t.rjust(offset, ' '), color)
88
89
  end
89
90
 
90
- def format_seconds(float, precision = nil)
91
- precision ||= (float < 1) ? 5 : 2
92
- sprintf("%.#{precision}f", float)
91
+ class Bullet
92
+ attr_accessor :message
93
+ def initialize(message = '', nested = false)
94
+ @t0 = RSpec::Core::Time.now
95
+ @nested = nested
96
+ @message = message
97
+ end
98
+
99
+ def delta_t
100
+ delta_t = RSpec::Core::Time.now - @t0
101
+ format_time(delta_t)
102
+ end
103
+
104
+ def offset
105
+ @message.size
106
+ end
107
+
108
+ def nest
109
+ @nested = true
110
+ end
111
+
112
+ def nested?
113
+ @nested
114
+ end
115
+
116
+ def format_time(duration)
117
+ if duration > 60
118
+ minutes = duration.to_i / 60
119
+ seconds = duration - minutes * 60
120
+ "#{minutes}m #{format_seconds(seconds)}s"
121
+ else
122
+ "#{format_seconds(duration)}s"
123
+ end
124
+ end
125
+
126
+ def format_seconds(float, precision = 2)
127
+ #precision ||= (float < 1) ? 5 : 2
128
+ sprintf("%.#{precision}f", float)
129
+ end
93
130
  end
94
131
  end
95
132
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module By
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -54,15 +54,38 @@ module RSpec::By
54
54
  end
55
55
  end
56
56
 
57
+ default_output = <<-EOS
58
+ root 0.01s
59
+ context 1 0.01s
60
+ nested example 1.1 0.01s
61
+ nested example 1.2 0.01s
62
+ knock knock 0.01s
63
+ who's there? 0.01s
64
+ 0.01s
65
+ by 0.01s
66
+ by who? 0.01s
67
+ 0.01s
68
+ by by 0.01s
69
+ 0.01s
70
+ context 1.1 0.01s
71
+ nested example 1.1.1 0.01s
72
+ nested example 1.1.2 0.01s
73
+ context 2 0.01s
74
+ nested example 2.1 0.01s
75
+ nested example 2.2 0.01s
76
+ EOS
77
+
57
78
  it "outputs correctly" do
58
79
  group = RSpec.describe("root")
59
80
  context1 = group.describe("context 1")
60
81
  context1.example("nested example 1.1"){}
61
82
  context1.example("nested example 1.2") do
62
- by('knock knock') {}
63
- and_by("who's there?") {}
64
- and_by('by') {}
65
- and_by('by who?') {}
83
+ by('knock knock') do
84
+ and_by("who's there?") {}
85
+ end
86
+ and_by('by') do
87
+ and_by('by who?') {}
88
+ end
66
89
  and_by('by by') {}
67
90
  end
68
91
 
@@ -78,29 +101,7 @@ module RSpec::By
78
101
 
79
102
  output = normalize_durations(formatter_output.string)
80
103
  output = remove_color(output)
81
- expect(output).to eq(normalize_durations("
82
- root
83
- context 1
84
- Example: nested example 1.1
85
- Passed 0.00022s
86
- Example: nested example 1.2
87
- knock knock 0.00022s
88
- who's there? 0.00022s
89
- by 0.00022s
90
- by who? 0.00022s
91
- by by 0.00022s
92
- Passed 0.00022s
93
- context 1.1
94
- Example: nested example 1.1.1
95
- Passed 0.00022s
96
- Example: nested example 1.1.2
97
- Passed 0.00022s
98
- context 2
99
- Example: nested example 2.1
100
- Passed 0.00022s
101
- Example: nested example 2.2
102
- Passed 0.00022s
103
- "))
104
+ expect(output).to eq(normalize_durations(default_output))
104
105
  end
105
106
  end
106
107
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Masaki Matsuo
@@ -13,15 +14,17 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec-core
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '3'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3'
27
30
  description: An RSpec formatter that provides step-like message output
@@ -30,8 +33,9 @@ executables: []
30
33
  extensions: []
31
34
  extra_rdoc_files: []
32
35
  files:
33
- - ".gitignore"
34
- - ".rspec"
36
+ - .gitignore
37
+ - .rspec
38
+ - .travis.yml
35
39
  - Gemfile
36
40
  - LICENSE
37
41
  - README.md
@@ -44,26 +48,27 @@ files:
44
48
  homepage: https://github.com/sleepn247/rspec-by
45
49
  licenses:
46
50
  - MIT
47
- metadata: {}
48
51
  post_install_message:
49
52
  rdoc_options: []
50
53
  require_paths:
51
54
  - lib
52
55
  required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
53
57
  requirements:
54
- - - ">="
58
+ - - ! '>='
55
59
  - !ruby/object:Gem::Version
56
60
  version: '0'
57
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
58
63
  requirements:
59
- - - ">="
64
+ - - ! '>='
60
65
  - !ruby/object:Gem::Version
61
66
  version: '0'
62
67
  requirements: []
63
68
  rubyforge_project:
64
- rubygems_version: 2.6.2
69
+ rubygems_version: 1.8.23.2
65
70
  signing_key:
66
- specification_version: 4
71
+ specification_version: 3
67
72
  summary: RSpec formatter
68
73
  test_files:
69
74
  - spec/rspec/by/formatter_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 9a240f474d6f0850c2b009b2ed17ffd1353c693b
4
- data.tar.gz: ce5ac170951b10ed93d4a5ce3181aa7c6ced7c4e
5
- SHA512:
6
- metadata.gz: d2aa9ae5ec968596cda13158c0d9060c2896657710560e2b3cfeee2a652be9b2f99d3e9396c1d926edac43458ff8e3053f4a62e5764f56e79e4ce92de21404d6
7
- data.tar.gz: bdf054b06d30a54e930c48db5cf5c6fbdaad3a0e871f3d44050c04b2c678b16fbc2131eb7186dd77a6397f5a192b478d7fd943054ddbbbb3e467342cf70b1871