rspec-longrun 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,40 +23,52 @@ Specify the custom output format when invoking RSpec, as follows:
23
23
  The resulting test output looks something like:
24
24
 
25
25
  Example group
26
- First example
26
+ * First example
27
27
  OK
28
- Second example
28
+ * Second example
29
29
  OK
30
- Third example
30
+ * Third example
31
31
  PENDING (Not implemented yet)
32
32
 
33
+
33
34
  ### Tracking progress
34
35
 
35
- RSpec::Longrun defines a 'step' method that can be used to group blocks of code within the context of a large test. For example:
36
+ Include RSpec::Longrun::DSL to define the 'step' method, which can be used to group blocks of code within the context of a large test. For example:
36
37
 
37
- example "Log in and alter preferences" do
38
+ describe "Account management" do
38
39
 
39
- step "Log in" do
40
- # ...
41
- end
40
+ include RSpec::Longrun::DSL # <-- important
42
41
 
43
- step "Navigate to preferences page" do
44
- # ...
45
- end
42
+ example "Log in and alter preferences" do
43
+
44
+ step "Log in" do
45
+ ui.go_home
46
+ ui.authenticate_as "joe", "fnord"
47
+ end
48
+
49
+ step "Navigate to preferences page" do
50
+ ui.nav.prefs_link.click
51
+ end
52
+
53
+ step "Change preferences" do
54
+ ui.prefs_pane.enter_defaults
55
+ ui.prefs_pane.save
56
+ end
46
57
 
47
- step "Change preferences" do
48
- # ...
49
58
  end
50
59
 
51
60
  end
52
61
 
53
62
  The resulting test output looks something like:
54
63
 
55
- Log in and alter preferences
56
- - Log in
57
- - Navigate to preferences page
58
- - Change preferences
59
- OK
64
+ Account management
65
+ * Log in and alter preferences
66
+ - Log in
67
+ - Navigate to preferences page
68
+ - Change preferences
69
+ OK
70
+
71
+ which gives you some extra context in the event that something fails, or hangs, during the test run.
60
72
 
61
73
  ## Contributing
62
74
 
@@ -0,0 +1,45 @@
1
+ require 'rspec/core/example'
2
+ require 'rspec/core/example_group'
3
+ require 'rspec/core/formatters/base_formatter'
4
+ require 'rspec/core/reporter'
5
+
6
+ # extend rspec-core with support for "steps"
7
+
8
+ module RSpec::Core
9
+
10
+ class Reporter
11
+
12
+ def step_started(description)
13
+ notify :step_started, description
14
+ end
15
+
16
+ def step_finished(description)
17
+ notify :step_finished, description
18
+ end
19
+
20
+ end
21
+
22
+ class Formatters::BaseFormatter
23
+
24
+ def step_started(description)
25
+ end
26
+
27
+ def step_finished(description)
28
+ end
29
+
30
+ end
31
+
32
+ class Example
33
+
34
+ private
35
+
36
+ alias :start_without_reporter :start
37
+
38
+ def start(reporter)
39
+ start_without_reporter(reporter)
40
+ @example_group_instance.instance_variable_set(:@_rspec_reporter, reporter)
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -1,58 +1,23 @@
1
- require 'rspec/core/example'
2
- require 'rspec/core/example_group'
3
- require 'rspec/core/formatters/base_formatter'
4
- require 'rspec/core/reporter'
1
+ require 'rspec/longrun/core_ext'
5
2
 
6
3
  # extend rspec-core with support for "steps"
7
4
 
8
- module RSpec::Core
5
+ module RSpec
6
+ module Longrun
7
+ module DSL
9
8
 
10
- class Reporter
9
+ private
11
10
 
12
- def step_started(description)
13
- notify :step_started, description
14
- end
15
-
16
- def step_finished(description)
17
- notify :step_finished, description
18
- end
19
-
20
- end
21
-
22
- class Formatters::BaseFormatter
11
+ def step(description)
12
+ pending(description) unless block_given?
13
+ begin
14
+ @_rspec_reporter.step_started(description)
15
+ yield
16
+ ensure
17
+ @_rspec_reporter.step_finished(description)
18
+ end
19
+ end
23
20
 
24
- def step_started(description)
25
21
  end
26
-
27
- def step_finished(description)
28
- end
29
-
30
22
  end
31
-
32
- class Example
33
-
34
- private
35
-
36
- alias :start_without_reporter :start
37
-
38
- def start(reporter)
39
- start_without_reporter(reporter)
40
- @example_group_instance.instance_variable_set(:@_rspec_reporter, reporter)
41
- end
42
-
43
- end
44
-
45
- class ExampleGroup
46
-
47
- private
48
-
49
- def step(description)
50
- @_rspec_reporter.step_started(description)
51
- yield if block_given?
52
- ensure
53
- @_rspec_reporter.step_finished(description)
54
- end
55
-
56
- end
57
-
58
23
  end
@@ -22,7 +22,7 @@ module RSpec
22
22
 
23
23
  def example_started(example)
24
24
  super(example)
25
- start_block(example.description)
25
+ start_block('* ' + cyan(example.description))
26
26
  end
27
27
 
28
28
  def example_passed(example)
@@ -32,7 +32,7 @@ module RSpec
32
32
 
33
33
  def example_pending(example)
34
34
  super(example)
35
- end_block(yellow("PENDING (#{example.execution_result[:pending_message]})"))
35
+ end_block(yellow("PENDING: " + example.execution_result[:pending_message]))
36
36
  end
37
37
 
38
38
  def example_failed(example)
@@ -41,7 +41,7 @@ module RSpec
41
41
  end
42
42
 
43
43
  def step_started(description)
44
- start_block('- ' + description)
44
+ start_block(faint('- ' + description))
45
45
  end
46
46
 
47
47
  def step_finished(description)
@@ -68,6 +68,10 @@ module RSpec
68
68
  ' ' * @indent_level
69
69
  end
70
70
 
71
+ def faint(text)
72
+ color(text, "\e[2m")
73
+ end
74
+
71
75
  end
72
76
 
73
77
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Longrun
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -3,6 +3,8 @@ require "stringio"
3
3
 
4
4
  describe RSpec::Longrun::Formatter do
5
5
 
6
+ include RSpec::Longrun::DSL
7
+
6
8
  let(:output_buffer) { StringIO.new }
7
9
  let(:formatter) { described_class.new(output_buffer) }
8
10
 
@@ -73,11 +75,11 @@ describe RSpec::Longrun::Formatter do
73
75
  it "outputs example names and status" do
74
76
  output.should eql(undent(<<-EOF))
75
77
  suite
76
- works
78
+ * works
77
79
  OK
78
- is unimplemented
79
- PENDING (implement me)
80
- fails
80
+ * is unimplemented
81
+ PENDING: implement me
82
+ * fails
81
83
  FAILED
82
84
  EOF
83
85
  end
@@ -88,6 +90,7 @@ describe RSpec::Longrun::Formatter do
88
90
 
89
91
  let(:suite) do
90
92
  RSpec::Core::ExampleGroup.describe("suite") do
93
+ include RSpec::Longrun::DSL
91
94
  example "has steps" do
92
95
  step "Collect underpants" do
93
96
  end
@@ -95,8 +98,7 @@ describe RSpec::Longrun::Formatter do
95
98
  step "(thinking)" do
96
99
  end
97
100
  end
98
- step "Profit!" do
99
- end
101
+ step "Profit!"
100
102
  end
101
103
  end
102
104
  end
@@ -105,12 +107,11 @@ describe RSpec::Longrun::Formatter do
105
107
  step "try steps" do
106
108
  output.should eql(undent(<<-EOF))
107
109
  suite
108
- has steps
110
+ * has steps
109
111
  - Collect underpants
110
112
  - Er ...
111
113
  - (thinking)
112
- - Profit!
113
- OK
114
+ PENDING: Profit!
114
115
  EOF
115
116
  end
116
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-longrun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -41,6 +41,7 @@ files:
41
41
  - README.md
42
42
  - Rakefile
43
43
  - lib/rspec/longrun.rb
44
+ - lib/rspec/longrun/core_ext.rb
44
45
  - lib/rspec/longrun/dsl.rb
45
46
  - lib/rspec/longrun/formatter.rb
46
47
  - lib/rspec/longrun/version.rb
@@ -60,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
61
  version: '0'
61
62
  segments:
62
63
  - 0
63
- hash: -754123683182328035
64
+ hash: -1671641901183265154
64
65
  required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  none: false
66
67
  requirements:
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  version: '0'
70
71
  segments:
71
72
  - 0
72
- hash: -754123683182328035
73
+ hash: -1671641901183265154
73
74
  requirements: []
74
75
  rubyforge_project:
75
76
  rubygems_version: 1.8.23