specify 0.10.2 → 1.0.0

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/Rakefile CHANGED
@@ -1,21 +1,25 @@
1
1
  #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
- require 'rdoc/task'
4
- require 'rubocop/rake_task'
5
- require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rdoc/task"
5
+ require "rubocop/rake_task"
6
+ require "rspec/core/rake_task"
6
7
 
7
8
  RuboCop::RakeTask.new
8
9
 
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
9
12
  namespace :spec do
10
13
  desc 'Clean all generated reports'
11
14
  task :clean do
12
15
  system('rm -rf spec/reports')
16
+ system('rm -rf spec/coverage')
13
17
  end
14
18
 
15
19
  RSpec::Core::RakeTask.new(all: :clean) do |config|
16
- options = %w(--color)
17
- options += %w(--format documentation)
18
- options += %w(--format html --out spec/reports/unit-test-report.html)
20
+ options = %w[--color]
21
+ options += %w[--format documentation]
22
+ options += %w[--format html --out spec/reports/test-report.html]
19
23
 
20
24
  config.rspec_opts = options
21
25
  end
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup'
4
- require 'specify'
3
+ require "bundler/setup"
4
+ require "specify"
5
5
 
6
- require 'pry'
6
+ require "pry"
7
7
  Pry.start
8
-
9
- # require 'irb'
10
- # IRB.start
data/bin/setup CHANGED
@@ -1,5 +1,8 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
+ set -vx
4
5
 
5
6
  bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,47 +1,36 @@
1
- require 'rspec/core'
2
- require 'rspec/core/world'
3
- require 'rspec/core/reporter'
4
- require 'rspec/core/formatters'
5
- require 'rspec/core/example_group'
6
- require 'rspec/core/formatters/console_codes'
7
- require 'rspec/core/formatters/documentation_formatter'
8
-
9
- require 'specify/spec'
10
- require 'specify/version'
11
- require 'specify/rspec/world'
12
- require 'specify/rspec/reporter'
13
- require 'specify/rspec/notification'
14
- require 'specify/rspec/example_group'
15
- require 'specify/rspec/documentation_formatter'
16
-
17
- RSpec::Core::ExampleGroup.send :include, RSpec::Specify::ExampleGroup
18
- RSpec::Core::Reporter.send :include, RSpec::Specify::Reporter
19
- RSpec::Core::World.send :include, RSpec::Specify::World
20
-
21
- RSpec::Core::Formatters::DocumentationFormatter.send :include, RSpec::Specify::DocumentationFormatter
22
-
23
- formatter = RSpec.world.reporter.find_registered_formatter(RSpec::Core::Formatters::DocumentationFormatter)
24
- RSpec.world.reporter.register_listener(
25
- formatter,
26
- :example_started,
27
- :example_step_passed,
28
- :example_step_pending,
29
- :example_step_failed,
30
- ) if formatter
31
-
32
- RSpec::Core::ExampleGroup.define_example_method :Scenario, with_steps: true
33
- RSpec::Core::ExampleGroup.define_example_method :Condition, with_steps: true
34
- RSpec::Core::ExampleGroup.define_example_method :Behavior, with_steps: true
35
-
36
- RSpec::Core::ExampleGroup.define_example_method :Step, with_steps: true
37
- RSpec::Core::ExampleGroup.define_example_method :Test, with_steps: true
38
- RSpec::Core::ExampleGroup.define_example_method :Rule, with_steps: true
39
- RSpec::Core::ExampleGroup.define_example_method :Fact, with_steps: true
40
-
41
- RSpec::Core::ExampleGroup.define_example_method :steps, with_steps: true
42
- RSpec::Core::ExampleGroup.define_example_method :rules, with_steps: true
43
- RSpec::Core::ExampleGroup.define_example_method :tests, with_steps: true
44
- RSpec::Core::ExampleGroup.define_example_method :facts, with_steps: true
45
-
46
- require 'specify/rspec/shared_steps'
47
- include RSpec::Specify::SharedSteps
1
+ require "specify/version"
2
+
3
+ require "specify/spec"
4
+ require "specify/rspec/world"
5
+ require "specify/rspec/reporter"
6
+ require "specify/rspec/formatter"
7
+ require "specify/rspec/notification"
8
+ require "specify/rspec/example_group"
9
+
10
+ require "specify/rspec/shared_steps"
11
+
12
+ module Specify
13
+ include RSpec::Specify::SharedSteps
14
+
15
+ ::RSpec::Core::ExampleGroup.define_example_method :Scenario, has_steps: true
16
+ ::RSpec::Core::ExampleGroup.define_example_method :Condition, has_steps: true
17
+ ::RSpec::Core::ExampleGroup.define_example_method :Behavior, has_steps: true
18
+
19
+ ::RSpec::Core::ExampleGroup.define_example_method :scenario, has_steps: true
20
+ ::RSpec::Core::ExampleGroup.define_example_method :condition, has_steps: true
21
+ ::RSpec::Core::ExampleGroup.define_example_method :behavior, has_steps: true
22
+
23
+ ::RSpec::Core::ExampleGroup.define_example_method :Steps, has_steps: true
24
+ ::RSpec::Core::ExampleGroup.define_example_method :Tests, has_steps: true
25
+ ::RSpec::Core::ExampleGroup.define_example_method :Rules, has_steps: true
26
+ ::RSpec::Core::ExampleGroup.define_example_method :Facts, has_steps: true
27
+
28
+ ::RSpec::Core::ExampleGroup.define_example_method :steps, has_steps: true
29
+ ::RSpec::Core::ExampleGroup.define_example_method :rules, has_steps: true
30
+ ::RSpec::Core::ExampleGroup.define_example_method :tests, has_steps: true
31
+ ::RSpec::Core::ExampleGroup.define_example_method :facts, has_steps: true
32
+
33
+ ::RSpec::Core::ExampleGroup.send :include, RSpec::Specify::ExampleGroup
34
+ ::RSpec::Core::Reporter.send :include, RSpec::Specify::Reporter
35
+ ::RSpec::Core::World.send :include, RSpec::Specify::World
36
+ end
@@ -1,85 +1,92 @@
1
1
  module RSpec
2
2
  module Specify
3
3
  module ExampleGroup
4
- # In Rspec, example group bodies are delimited by 'describe' and
5
- # 'context' methods. These encapsulate examples, which are
6
- # delimited by 'it' methods. Example groups are evaluated in the
7
- # context of an ExampleGroup instance. Individual examples are
8
- # evaluated in the context of an instance of the ExampleGroup
9
- # to which they belong.
10
-
11
4
  def include_steps(*args)
12
5
  name = args.shift
6
+
13
7
  shared_block = ::RSpec.world.shared_example_steps[name]
14
- shared_block || raise(ArgumentError, "Could not find shared steps #{name.inspect}")
8
+ shared_block || raise(ArgumentError,
9
+ "Unable to find shared steps '#{name.inspect}'")
10
+
15
11
  instance_exec(*args, &shared_block)
16
12
  end
17
13
 
14
+ # rubocop:disable Naming/MethodName
18
15
  def Given(message, options = {}, &block)
19
- Action :given, message, options, &block
16
+ run_example_step(:given, message, options, &block)
20
17
  end
21
18
 
22
19
  def When(message, options = {}, &block)
23
- Action :when, message, options, &block
20
+ run_example_step(:when, message, options, &block)
24
21
  end
25
22
 
26
23
  def Then(message, options = {}, &block)
27
- Action :then, message, options, &block
24
+ run_example_step(:then, message, options, &block)
28
25
  end
29
26
 
30
27
  def And(message, options = {}, &block)
31
- Action :and, message, options, &block
28
+ run_example_step(:and, message, options, &block)
32
29
  end
33
30
 
34
31
  def But(message, options = {}, &block)
35
- Action :but, message, options, &block
32
+ run_example_step(:but, message, options, &block)
36
33
  end
34
+ # rubocop:enable Naming/MethodName
37
35
 
38
- def it(message, options = {}, &block)
39
- Action :it, message, options, &block
36
+ def rule(message, options = {}, &block)
37
+ run_example_step(:rule, message, options, &block)
40
38
  end
41
39
 
42
- def specify(message, options = {}, &block)
43
- Action :specify, message, options, &block
40
+ def fact(message, options = {}, &block)
41
+ run_example_step(:fact, message, options, &block)
44
42
  end
45
43
 
46
- def example(message, options = {}, &block)
47
- Action :example, message, options, &block
44
+ def test(message, options = {}, &block)
45
+ run_example_step(:test, message, options, &block)
48
46
  end
49
47
 
50
- def rule(message, options = {}, &block)
51
- Action :rule, message, options, &block
48
+ def step(message, options = {}, &block)
49
+ run_example_step(:step, message, options, &block)
52
50
  end
53
51
 
54
- def fact(message, options = {}, &block)
55
- Action :fact, message, options, &block
52
+ def it(message, options = {}, &block)
53
+ run_example_step(:it, message, options, &block)
56
54
  end
57
55
 
58
- def test(message, options = {}, &block)
59
- Action :test, message, options, &block
56
+ def specify(message, options = {}, &block)
57
+ run_example_step(:specify, message, options, &block)
60
58
  end
61
59
 
62
- def step(message, options = {}, &block)
63
- Action :step, message, options, &block
60
+ def example(message, options = {}, &block)
61
+ run_example_step(:example, message, options, &block)
64
62
  end
65
63
 
66
64
  private
67
65
 
68
- def Action(type, message, options = {}, &_block)
69
- ::RSpec.world.reporter.example_step_started(self, type, message, options)
70
- options = { pending: true } if options == :pending
71
-
72
- if block_given? && !options[:pending]
73
- begin
74
- yield
75
- rescue Exception => e
76
- ::RSpec.world.reporter.example_step_failed(self, type, message, options)
77
- raise e
78
- end
79
- ::RSpec.world.reporter.example_step_passed(self, type, message, options)
66
+ def run_example_step(type, msg, opts = {}, &block)
67
+ ::RSpec.world.reporter.example_step_started(self, type, msg, opts)
68
+
69
+ opts = { pending: true } if opts == :pending
70
+
71
+ if block_given? && !opts[:pending]
72
+ execute_step(type, msg, opts, &block)
80
73
  else
81
- ::RSpec.world.reporter.example_step_pending(self, type, message, options)
74
+ ::RSpec.world.reporter.example_step_pending(
75
+ self, type, msg, opts
76
+ )
77
+ end
78
+ end
79
+
80
+ def execute_step(type, msg, opts, &_block)
81
+ begin
82
+ yield
83
+ # rubocop:disable Lint/RescueException
84
+ rescue Exception => e
85
+ ::RSpec.world.reporter.example_step_failed(self, type, msg, opts)
86
+ raise e
82
87
  end
88
+ # rubocop:enable Lint/RescueException
89
+ ::RSpec.world.reporter.example_step_passed(self, type, msg, opts)
83
90
  end
84
91
  end
85
92
  end
@@ -0,0 +1,72 @@
1
+ require "rspec/core/formatters/console_codes"
2
+ require "rspec/core/formatters/documentation_formatter"
3
+
4
+ module RSpec
5
+ module Specify
6
+ class Formatter < ::RSpec::Core::Formatters::DocumentationFormatter
7
+ ::RSpec::Core::Formatters.register(
8
+ self,
9
+ :example_started, :example_passed,
10
+ :example_step_passed, :example_step_failed,
11
+ :example_step_pending
12
+ )
13
+
14
+ def example_started(notification)
15
+ return unless notification.example.metadata[:has_steps]
16
+
17
+ indentation = current_indentation
18
+ description = notification.example.description
19
+
20
+ full_message = "#{indentation}#{description}"
21
+ output.puts(
22
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap(full_message, :default)
23
+ )
24
+ end
25
+
26
+ def example_passed(notification)
27
+ super unless notification.example.metadata[:has_steps]
28
+ end
29
+
30
+ def example_step_passed(notification)
31
+ indentation = current_indentation
32
+ step_type = notification.type.to_s.capitalize
33
+ step_message = notification.message
34
+
35
+ full_message = "#{indentation} #{step_type} #{step_message}"
36
+ output.puts(
37
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap(full_message, :success)
38
+ )
39
+ end
40
+
41
+ def example_step_failed(notification)
42
+ indentation = current_indentation
43
+ step_type = notification.type.to_s.capitalize
44
+ step_message = notification.message
45
+
46
+ full_message = "#{indentation} #{step_type} #{step_message} (FAILED)"
47
+ output.puts(
48
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap(full_message, :failure)
49
+ )
50
+ end
51
+
52
+ def example_step_pending(notification)
53
+ indentation = current_indentation
54
+ step_type = notification.type.to_s.capitalize
55
+ step_message = notification.message
56
+
57
+ full_message = "#{indentation} #{step_type} #{step_message}"
58
+
59
+ full_message << if notification.options[:pending] &&
60
+ notification.options[:pending] != true
61
+ " (PENDING: #{notification.options[:pending]})"
62
+ else
63
+ " (PENDING)"
64
+ end
65
+
66
+ output.puts(
67
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap(full_message, :pending)
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,8 +1,5 @@
1
1
  module RSpec
2
2
  module Specify
3
- # In RSpec, notifications are value objects that are passed to formatters
4
- # to provide those formatters with information about a particular event.
5
-
6
3
  Notification = Struct.new(:example, :type, :message, :options)
7
4
  end
8
5
  end
@@ -1,31 +1,24 @@
1
1
  module RSpec
2
2
  module Specify
3
3
  module Reporter
4
- # An RSpec reporter sends notifications to listeners. The listeners
5
- # are usually formatters for a specific test run.
6
-
7
4
  def example_step_started(example, type, message, options)
8
- notify :example_step_started, Notification.new(example, type, message, options)
5
+ notify :example_step_started,
6
+ Notification.new(example, type, message, options)
9
7
  end
10
8
 
11
9
  def example_step_passed(example, type, message, options)
12
- notify :example_step_passed, Notification.new(example, type, message, options)
10
+ notify :example_step_passed,
11
+ Notification.new(example, type, message, options)
13
12
  end
14
13
 
15
14
  def example_step_failed(example, type, message, options)
16
- notify :example_step_failed, Notification.new(example, type, message, options)
15
+ notify :example_step_failed,
16
+ Notification.new(example, type, message, options)
17
17
  end
18
18
 
19
19
  def example_step_pending(example, type, message, options)
20
- notify :example_step_pending, Notification.new(example, type, message, options)
21
- end
22
-
23
- def registered_formatters
24
- @listeners.values.map(&:to_a).flatten.uniq
25
- end
26
-
27
- def find_registered_formatter(cls)
28
- registered_formatters.detect { |formatter| formatter.class == cls }
20
+ notify :example_step_pending,
21
+ Notification.new(example, type, message, options)
29
22
  end
30
23
  end
31
24
  end
@@ -10,10 +10,8 @@ module RSpec
10
10
 
11
11
  def ensure_shared_example_steps_name_not_taken(name)
12
12
  return unless ::RSpec.world.shared_example_steps.key?(name)
13
+
13
14
  raise(ArgumentError, "Shared step '#{name}' already exists")
14
- # if ::RSpec.world.shared_example_steps.key?(name)
15
- # raise ArgumentError.new("Shared step '#{name}' already exists")
16
- # end
17
15
  end
18
16
  end
19
17
  end
@@ -1,9 +1,6 @@
1
1
  module RSpec
2
2
  module Specify
3
3
  module World
4
- # RSpec's world is an internal container for global
5
- # non-configuration data.
6
-
7
4
  def shared_example_steps
8
5
  @shared_example_steps ||= {}
9
6
  end
@@ -1,39 +1,45 @@
1
1
  module Specify
2
2
  module Spec
3
- def self.included(base)
4
- base.instance_eval do
5
- alias :Background :before
6
- alias :Setup :before
7
- alias :Teardown :after
8
-
3
+ # rubocop:disable Metrics/MethodLength
4
+ def self.included(caller)
5
+ caller.instance_eval do
9
6
  alias :Feature :context
7
+ alias :feature :context
10
8
  alias :Ability :context
11
- alias :Story :context
9
+ alias :ability :context
12
10
  alias :Component :context
11
+ alias :component :context
13
12
  alias :Workflow :context
13
+ alias :workflow :context
14
+ alias :Service :context
15
+ alias :service :context
16
+
17
+ alias :Background :before
18
+ alias :Setup :before
19
+ alias :Teardown :after
20
+ alias :Cleanup :after
14
21
  end
15
22
  end
23
+ # rubocop:enable Metrics/MethodLength
16
24
  end
17
25
  end
18
26
 
27
+ # rubocop:disable Naming/MethodName
19
28
  def self.Feature(*args, &block)
20
- describe(*args, &block)
29
+ RSpec.describe(*args, &block)
21
30
  end
22
31
 
23
- def self.Ability(*args, &block)
24
- describe(*args, &block)
32
+ def self.feature(*args, &block)
33
+ RSpec.describe(*args, &block)
25
34
  end
26
35
 
27
36
  def self.Story(*args, &block)
28
- describe(*args, &block)
29
- end
30
-
31
- def self.Component(*args, &block)
32
- describe(*args, &block)
37
+ RSpec.describe(*args, &block)
33
38
  end
34
39
 
35
- def self.Workflow(*args, &block)
36
- describe(*args, &block)
40
+ def self.story(*args, &block)
41
+ RSpec.describe(*args, &block)
37
42
  end
43
+ # rubocop:enable Naming/MethodName
38
44
 
39
45
  RSpec.configuration.include Specify::Spec