rspec_in_context 0.3.2 → 1.0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.git-hooks/pre_push/rubocop.rb +18 -0
- data/.github/workflows/test_and_publish.yml +88 -0
- data/.github/workflows/test_only.yml +68 -0
- data/.github/workflows/verify_version_change.yml +21 -0
- data/.overcommit.yml +3 -1
- data/.rubocop-http---relaxed-ruby-style-rubocop-yml +11 -24
- data/.rubocop.yml +46 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +15 -0
- data/README.md +2 -2
- data/lib/rspec_in_context.rb +10 -0
- data/lib/rspec_in_context/context_management.rb +7 -0
- data/lib/rspec_in_context/in_context.rb +45 -0
- data/lib/rspec_in_context/version.rb +2 -1
- data/rspec_in_context.gemspec +13 -10
- metadata +63 -33
- data/.circleci/config.yml +0 -81
- data/.circleci/setup-rubygems.sh +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08306b0c06181ef96f4acdc36980f27792715378cb624eb7ba633c4945e90c7e'
|
4
|
+
data.tar.gz: 2cd8c33b01f3ebcb9720e43bcc4cba0fc4562808681f040ca10cc47816e33c27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c91690c0ad28afc64c1999a1bcdfa6c0e51556f808b7cf337ea9d2ec59ebf01b50d03a492bd96957596d319a1a69204232a001bc432c6001c5cd6a69e0b4316
|
7
|
+
data.tar.gz: 4d3b90906fbe61f9485c6f415e86b24dbb7d44343e87c0015915899f384bbae10f1044fbcf4b90cb585ef238fbbee65edb1e4b573968804d8f77a8a7203233be
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit
|
4
|
+
module Hook
|
5
|
+
module PrePush
|
6
|
+
# Runs `rubocop` on every files.
|
7
|
+
class Rubocop < Base
|
8
|
+
def run
|
9
|
+
result = execute(['rubocop', '-P'])
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
[:fail, output]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
name: Test and Release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test-2_5:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.5
|
18
|
+
- name: Install dependencies
|
19
|
+
run: bundle install
|
20
|
+
- name: Run linter
|
21
|
+
run: bundle exec rubocop
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rspec
|
24
|
+
test-2_6:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: 2.6
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run linter
|
36
|
+
run: bundle exec rubocop
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rspec
|
39
|
+
test-2_7:
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- name: Set up Ruby
|
45
|
+
uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: 2.7
|
48
|
+
- name: Install dependencies
|
49
|
+
run: bundle install
|
50
|
+
- name: Run linter
|
51
|
+
run: bundle exec rubocop
|
52
|
+
- name: Run tests
|
53
|
+
run: bundle exec rspec
|
54
|
+
test-3_0:
|
55
|
+
runs-on: ubuntu-latest
|
56
|
+
|
57
|
+
steps:
|
58
|
+
- uses: actions/checkout@v2
|
59
|
+
- name: Set up Ruby
|
60
|
+
uses: ruby/setup-ruby@v1
|
61
|
+
with:
|
62
|
+
ruby-version: 3.0
|
63
|
+
- name: Install dependencies
|
64
|
+
run: bundle install
|
65
|
+
- name: Run linter
|
66
|
+
run: bundle exec rubocop
|
67
|
+
- name: Run tests
|
68
|
+
run: bundle exec rspec
|
69
|
+
release:
|
70
|
+
needs: [test-2_5, test-2_6, test-2_7, test-3_0]
|
71
|
+
runs-on: ubuntu-latest
|
72
|
+
|
73
|
+
steps:
|
74
|
+
- uses: actions/checkout@v2
|
75
|
+
- name: Set up Ruby
|
76
|
+
uses: ruby/setup-ruby@v1
|
77
|
+
with:
|
78
|
+
ruby-version: 3.0
|
79
|
+
- name: Install dependencies
|
80
|
+
run: bundle install
|
81
|
+
- name: Prepare credentials
|
82
|
+
env:
|
83
|
+
RUBYGEM_KEY: ${{ secrets.RUBYGEM_KEY }}
|
84
|
+
run: "mkdir -p ~/.gem && echo -e \"---\\r\\n:rubygems_api_key: $RUBYGEM_KEY\" > ~/.gem/credentials && chmod 0600 ~/.gem/credentials"
|
85
|
+
- name: Setup username/email
|
86
|
+
run: "git config --global user.email zaratan@hey.com && git config --global user.name \"Denis <Zaratan> Pasin\""
|
87
|
+
- name: Publish
|
88
|
+
run: rake release
|
@@ -0,0 +1,68 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches-ignore:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test-2_5:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.5
|
18
|
+
- name: Install dependencies
|
19
|
+
run: bundle install
|
20
|
+
- name: Run linter
|
21
|
+
run: bundle exec rubocop
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rspec
|
24
|
+
test-2_6:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: 2.6
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run linter
|
36
|
+
run: bundle exec rubocop
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rspec
|
39
|
+
test-2_7:
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- name: Set up Ruby
|
45
|
+
uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: 2.7
|
48
|
+
- name: Install dependencies
|
49
|
+
run: bundle install
|
50
|
+
- name: Run linter
|
51
|
+
run: bundle exec rubocop
|
52
|
+
- name: Run tests
|
53
|
+
run: bundle exec rspec
|
54
|
+
test-3_0:
|
55
|
+
runs-on: ubuntu-latest
|
56
|
+
|
57
|
+
steps:
|
58
|
+
- uses: actions/checkout@v2
|
59
|
+
- name: Set up Ruby
|
60
|
+
uses: ruby/setup-ruby@v1
|
61
|
+
with:
|
62
|
+
ruby-version: 3.0
|
63
|
+
- name: Install dependencies
|
64
|
+
run: bundle install
|
65
|
+
- name: Run linter
|
66
|
+
run: bundle exec rubocop
|
67
|
+
- name: Run tests
|
68
|
+
run: bundle exec rspec
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Verify version change
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
version_change:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Fetch main branch
|
15
|
+
run: git fetch origin main:main
|
16
|
+
- name: Verify if there's a change in version
|
17
|
+
run: "git diff main lib/rspec_in_context/version.rb | grep VERSION"
|
18
|
+
- name: Print new version
|
19
|
+
run: 'git diff main lib/rspec_in_context/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?"'
|
20
|
+
- name: Verify if higher version
|
21
|
+
run: '[[ $(git diff main lib/rspec_in_context/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") > $(git diff main lib/rspec_in_context/version.rb | grep -E "^-.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") ]]'
|
data/.overcommit.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PreCommit:
|
2
2
|
RuboCop:
|
3
3
|
enabled: true
|
4
|
-
command: ['bundle', 'exec', 'rubocop'] # Invoke within Bundler context
|
4
|
+
command: ['bundle', 'exec', 'rubocop', '-P'] # Invoke within Bundler context
|
5
5
|
BundleOutdated:
|
6
6
|
enabled: true
|
7
7
|
BundleAudit:
|
@@ -10,3 +10,5 @@ PrePush:
|
|
10
10
|
RSpec:
|
11
11
|
enabled: true
|
12
12
|
command: ['bundle', 'exec', 'rspec'] # Invoke within Bundler context
|
13
|
+
Rubocop:
|
14
|
+
enabled: true
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Relaxed.Ruby.Style
|
2
|
-
## Version 2.
|
2
|
+
## Version 2.5
|
3
3
|
|
4
4
|
Style/Alias:
|
5
5
|
Enabled: false
|
@@ -65,6 +65,10 @@ Style/NegatedWhile:
|
|
65
65
|
Enabled: false
|
66
66
|
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
|
67
67
|
|
68
|
+
Style/NumericPredicate:
|
69
|
+
Enabled: false
|
70
|
+
StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate
|
71
|
+
|
68
72
|
Style/ParallelAssignment:
|
69
73
|
Enabled: false
|
70
74
|
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
|
@@ -121,6 +125,10 @@ Style/TrailingCommaInHashLiteral:
|
|
121
125
|
Enabled: false
|
122
126
|
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
|
123
127
|
|
128
|
+
Style/SymbolArray:
|
129
|
+
Enabled: false
|
130
|
+
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
|
131
|
+
|
124
132
|
Style/WhileUntilModifier:
|
125
133
|
Enabled: false
|
126
134
|
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
|
@@ -137,30 +145,9 @@ Lint/AssignmentInCondition:
|
|
137
145
|
Enabled: false
|
138
146
|
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
|
139
147
|
|
140
|
-
|
141
|
-
Enabled: false
|
142
|
-
|
143
|
-
Metrics/BlockNesting:
|
144
|
-
Enabled: false
|
145
|
-
|
146
|
-
Metrics/ClassLength:
|
147
|
-
Enabled: false
|
148
|
-
|
149
|
-
Metrics/ModuleLength:
|
150
|
-
Enabled: false
|
151
|
-
|
152
|
-
Metrics/CyclomaticComplexity:
|
153
|
-
Enabled: false
|
154
|
-
|
155
|
-
Metrics/LineLength:
|
156
|
-
Enabled: false
|
157
|
-
|
158
|
-
Metrics/MethodLength:
|
159
|
-
Enabled: false
|
160
|
-
|
161
|
-
Metrics/ParameterLists:
|
148
|
+
Layout/LineLength:
|
162
149
|
Enabled: false
|
163
150
|
|
164
|
-
Metrics
|
151
|
+
Metrics:
|
165
152
|
Enabled: false
|
166
153
|
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
inherit_from:
|
2
2
|
- http://relaxed.ruby.style/rubocop.yml
|
3
3
|
|
4
|
+
require:
|
5
|
+
- rubocop-performance
|
6
|
+
|
4
7
|
AllCops:
|
8
|
+
NewCops: enable
|
5
9
|
DisplayStyleGuide: true
|
6
10
|
DisplayCopNames: true
|
7
11
|
Exclude:
|
8
|
-
- 'db/schema.rb'
|
9
|
-
- 'vendor/**/*'
|
10
|
-
- 'config/environments/*.rb'
|
11
12
|
- 'bin/*'
|
12
13
|
|
13
14
|
Metrics/BlockLength:
|
@@ -17,5 +18,46 @@ Metrics/BlockLength:
|
|
17
18
|
- 'vendor/bundle'
|
18
19
|
- '*.gemspec'
|
19
20
|
|
20
|
-
Naming/
|
21
|
+
Naming/MethodParameterName:
|
21
22
|
Enabled: false
|
23
|
+
|
24
|
+
Layout/DotPosition:
|
25
|
+
Enabled: true
|
26
|
+
EnforcedStyle: trailing
|
27
|
+
|
28
|
+
Style/TrailingCommaInArrayLiteral:
|
29
|
+
Enabled: true
|
30
|
+
EnforcedStyleForMultiline: comma
|
31
|
+
|
32
|
+
Style/TrailingCommaInHashLiteral:
|
33
|
+
Enabled: true
|
34
|
+
EnforcedStyleForMultiline: comma
|
35
|
+
|
36
|
+
Layout/MultilineArrayLineBreaks:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Layout/MultilineHashKeyLineBreaks:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Layout/MultilineMethodArgumentLineBreaks:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Layout/FirstArrayElementLineBreak:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Layout/FirstHashElementLineBreak:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Layout/FirstMethodArgumentLineBreak:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Layout/MultilineAssignmentLayout:
|
55
|
+
Enabled: true
|
56
|
+
|
57
|
+
Layout/LineLength:
|
58
|
+
Enabled: true
|
59
|
+
Max: 120
|
60
|
+
AutoCorrect: true
|
61
|
+
Exclude:
|
62
|
+
- Gemfile
|
63
|
+
- Guardfile
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [1.0.1.2] - 2020-12-26
|
10
|
+
### Added
|
11
|
+
- Changelog
|
12
|
+
- Support ruby 3.0
|
13
|
+
|
14
|
+
[Unreleased]: https://github.com/zaratan/active_shotgun/compare/v1.0.1.2...HEAD
|
15
|
+
[1.0.1.2]: https://github.com/zaratan/active_shotgun/releases/tag/v1.0.1.2
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# RspecInContext
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/rspec_in_context.svg)](https://badge.fury.io/rb/rspec_in_context)
|
4
|
-
[![Codacy Badge](https://
|
5
|
-
|
4
|
+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6490834b08664dc898d0107c74a78357)](https://www.codacy.com/gh/zaratan/rspec_in_context/dashboard?utm_source=github.com&utm_medium=referral&utm_content=zaratan/rspec_in_context&utm_campaign=Badge_Grade)
|
5
|
+
![Test and Release badge](https://github.com/zaratan/rspec_in_context/workflows/Test%20and%20Release/badge.svg)
|
6
6
|
|
7
7
|
This gem is here to help you write better shared_examples in Rspec.
|
8
8
|
|
data/lib/rspec_in_context.rb
CHANGED
@@ -5,13 +5,23 @@ require "rspec_in_context/version"
|
|
5
5
|
require "rspec_in_context/in_context"
|
6
6
|
require "rspec_in_context/context_management"
|
7
7
|
|
8
|
+
# Main wrapping module
|
8
9
|
module RspecInContext
|
10
|
+
# @api private
|
11
|
+
# Inclusion convenience of the gem in RSpec
|
9
12
|
def self.included(base)
|
10
13
|
base.include(RspecInContext::InContext)
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
17
|
+
# RSpec
|
14
18
|
module RSpec
|
19
|
+
# Allows you to define contexts outside of RSpec.describe blocks
|
20
|
+
#
|
21
|
+
# @param name [String, Symbol] Name of the defined context
|
22
|
+
# @param namespace [String, Symbol] Namespace where to store your context
|
23
|
+
# @param ns Alias of namespace
|
24
|
+
# @param block [Proc] code that will be injected later
|
15
25
|
def self.define_context(name, namespace: nil, ns: nil, &block)
|
16
26
|
namespace ||= ns
|
17
27
|
RspecInContext::InContext.outside_define_context(name, namespace, &block)
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RspecInContext
|
4
|
+
# Allow context to be scoped inside a block
|
4
5
|
module ContextManagement
|
6
|
+
# @api private
|
7
|
+
# prepending a RSpec method so we can know when a describe/context block finish
|
8
|
+
# its reading
|
5
9
|
def subclass(parent, description, args, registration_collection, &example_group_block)
|
6
10
|
subclass = super
|
7
11
|
RspecInContext::InContext.remove_context(subclass)
|
@@ -11,9 +15,12 @@ module RspecInContext
|
|
11
15
|
end
|
12
16
|
|
13
17
|
module RSpec
|
18
|
+
# Core
|
14
19
|
module Core
|
20
|
+
# ExampleGroup
|
15
21
|
class ExampleGroup
|
16
22
|
class << self
|
23
|
+
# allow context management to work
|
17
24
|
prepend RspecInContext::ContextManagement
|
18
25
|
end
|
19
26
|
end
|
@@ -1,25 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Base module
|
3
4
|
module RspecInContext
|
5
|
+
# Error type when no context is find from its name (and eventualy namespace)
|
4
6
|
class NoContextFound < StandardError; end
|
7
|
+
|
8
|
+
# Context struct
|
5
9
|
Context = Struct.new(:block, :owner, :name, :namespace)
|
10
|
+
|
11
|
+
# Main module containing almost every methods
|
6
12
|
module InContext
|
13
|
+
# Name of the Global context
|
7
14
|
GLOBAL_CONTEXT = :global_context
|
8
15
|
class << self
|
16
|
+
# Hook for easier inclusion of the gem in RSpec
|
17
|
+
# @api private
|
9
18
|
def included(base)
|
10
19
|
base.extend ClassMethods
|
11
20
|
end
|
12
21
|
|
22
|
+
# Contexts container + creation
|
23
|
+
# @api private
|
13
24
|
def contexts
|
14
25
|
@contexts ||= HashWithIndifferentAccess.new { |hash, key| hash[key] = HashWithIndifferentAccess.new }
|
15
26
|
end
|
16
27
|
|
28
|
+
# Meta method to add a new context
|
29
|
+
# @api private
|
30
|
+
#
|
31
|
+
# @note Will warn if a context is overriden
|
17
32
|
def add_context(context_name, owner = nil, namespace = nil, &block)
|
18
33
|
namespace ||= GLOBAL_CONTEXT
|
19
34
|
warn("Overriding an existing context: #{context_name}@#{namespace}") if contexts[namespace][context_name]
|
20
35
|
contexts[namespace][context_name] = Context.new(block, owner, context_name, namespace)
|
21
36
|
end
|
22
37
|
|
38
|
+
# Find a context.
|
39
|
+
# @api private
|
23
40
|
def find_context(context_name, namespace = nil)
|
24
41
|
if namespace&.present?
|
25
42
|
contexts[namespace][context_name]
|
@@ -29,23 +46,37 @@ module RspecInContext
|
|
29
46
|
(raise NoContextFound, "No context found with name #{context_name}")
|
30
47
|
end
|
31
48
|
|
49
|
+
# Look into every namespace to find the context
|
50
|
+
# @api private
|
32
51
|
def find_context_in_any_namespace(context_name)
|
33
52
|
valid_namespace = contexts.find{ |_, namespaced_contexts| namespaced_contexts[context_name] }&.last
|
34
53
|
valid_namespace[context_name] if valid_namespace
|
35
54
|
end
|
36
55
|
|
56
|
+
# @api private
|
57
|
+
# Delete a context
|
37
58
|
def remove_context(current_class)
|
38
59
|
contexts.each_value do |namespaced_contexts|
|
39
60
|
namespaced_contexts.delete_if{ |_, context| context.owner == current_class }
|
40
61
|
end
|
41
62
|
end
|
42
63
|
|
64
|
+
# @api private
|
65
|
+
# Define a context from outside a RSpec.describe block
|
43
66
|
def outside_define_context(context_name, namespace, &block)
|
44
67
|
InContext.add_context(context_name, nil, namespace, &block)
|
45
68
|
end
|
46
69
|
end
|
47
70
|
|
71
|
+
# This module define the methods that will be available for the end user inside RSpec tests
|
48
72
|
module ClassMethods
|
73
|
+
# Use a context and inject its content at this place in the code
|
74
|
+
#
|
75
|
+
# @param [String, Symbol] context_name The context namespace
|
76
|
+
# @param [*Any] args Any arg to be passed down to the injected context
|
77
|
+
# @param [String, Symbol] namespace namespace name where to look for the context
|
78
|
+
# @param [String, Symbol] ns Alias for :namespace
|
79
|
+
# @param block Content that will be re-injected (see #execute_tests)
|
49
80
|
def in_context(context_name, *args, namespace: nil, ns: nil, &block)
|
50
81
|
namespace ||= ns
|
51
82
|
Thread.current[:test_block] = block
|
@@ -54,11 +85,25 @@ module RspecInContext
|
|
54
85
|
end
|
55
86
|
end
|
56
87
|
|
88
|
+
# Used in context definition
|
89
|
+
# Place where you want to re-inject code passed in argument of in_context
|
90
|
+
#
|
91
|
+
# For convenience and readability, a `instanciate_context` alias have been defined
|
92
|
+
# (for more examples look at tests)
|
57
93
|
def execute_tests
|
58
94
|
instance_exec(&Thread.current[:test_block]) if Thread.current[:test_block]
|
59
95
|
end
|
60
96
|
alias_method :instanciate_context, :execute_tests
|
61
97
|
|
98
|
+
# Let you define a context that can be reused later
|
99
|
+
#
|
100
|
+
# @param context_name [String, Symbol] The name of the context that will be re-used later
|
101
|
+
# @param namespace [String, Symbol] namespace name where the context will be stored.
|
102
|
+
# It helps reducing colisions when you define "global" contexts
|
103
|
+
# @param ns [String, Symbol] Alias of namespace
|
104
|
+
# @param block [Proc] Contain the code that will be injected with #in_context later
|
105
|
+
#
|
106
|
+
# @note contexts are scoped to the block they are defined in.
|
62
107
|
def define_context(context_name, namespace: nil, ns: nil, &block)
|
63
108
|
namespace ||= ns
|
64
109
|
instance_exec do
|
data/rspec_in_context.gemspec
CHANGED
@@ -15,27 +15,30 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
# Specify which files should be added to the gem when it is released.
|
17
17
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files =
|
19
|
-
|
20
|
-
|
18
|
+
spec.files =
|
19
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
21
22
|
spec.bindir = "exe"
|
22
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
24
|
spec.require_paths = ["lib"]
|
24
|
-
spec.required_ruby_version = '>= 2.
|
25
|
+
spec.required_ruby_version = '>= 2.5.8' # rubocop:disable Gemspec/RequiredRubyVersion
|
25
26
|
spec.license = 'MIT'
|
26
27
|
|
27
28
|
spec.add_dependency "activesupport", "> 2.0"
|
28
29
|
spec.add_dependency "rspec", "> 3.0"
|
29
30
|
|
30
|
-
spec.add_development_dependency "bundler"
|
31
|
-
spec.add_development_dependency "bundler-audit", "
|
32
|
-
spec.add_development_dependency "codacy-coverage", '
|
31
|
+
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "bundler-audit", "> 0.6.0"
|
33
|
+
spec.add_development_dependency "codacy-coverage", '>= 2.1.0'
|
33
34
|
spec.add_development_dependency "faker", "> 1.8"
|
34
35
|
spec.add_development_dependency "guard-rspec", "> 4.7"
|
35
|
-
spec.add_development_dependency "
|
36
|
-
spec.add_development_dependency "
|
37
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "overcommit", '> 0.46'
|
37
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
38
38
|
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
|
39
39
|
spec.add_development_dependency "rubocop", "> 0.58"
|
40
|
+
spec.add_development_dependency "rubocop-performance"
|
40
41
|
spec.add_development_dependency "simplecov", "> 0.16"
|
42
|
+
spec.add_development_dependency "solargraph"
|
43
|
+
spec.add_development_dependency "yard"
|
41
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_in_context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis <Zaratan> Pasin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -42,42 +42,42 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler-audit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.6.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.6.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: codacy-coverage
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 2.1.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.1.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
@@ -108,32 +108,18 @@ dependencies:
|
|
108
108
|
- - ">"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '4.7'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: guard-rubocop
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '1.3'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '1.3'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: overcommit
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- - "
|
115
|
+
- - ">"
|
130
116
|
- !ruby/object:Gem::Version
|
131
117
|
version: '0.46'
|
132
118
|
type: :development
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
|
-
- - "
|
122
|
+
- - ">"
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0.46'
|
139
125
|
- !ruby/object:Gem::Dependency
|
@@ -142,14 +128,14 @@ dependencies:
|
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
131
|
+
version: '12.0'
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
138
|
+
version: '12.0'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: rspec_junit_formatter
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +164,20 @@ dependencies:
|
|
178
164
|
- - ">"
|
179
165
|
- !ruby/object:Gem::Version
|
180
166
|
version: '0.58'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-performance
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: simplecov
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +192,34 @@ dependencies:
|
|
192
192
|
- - ">"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0.16'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: solargraph
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: yard
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
195
223
|
description:
|
196
224
|
email:
|
197
225
|
- denis@pasin.fr
|
@@ -199,8 +227,10 @@ executables: []
|
|
199
227
|
extensions: []
|
200
228
|
extra_rdoc_files: []
|
201
229
|
files:
|
202
|
-
- ".
|
203
|
-
- ".
|
230
|
+
- ".git-hooks/pre_push/rubocop.rb"
|
231
|
+
- ".github/workflows/test_and_publish.yml"
|
232
|
+
- ".github/workflows/test_only.yml"
|
233
|
+
- ".github/workflows/verify_version_change.yml"
|
204
234
|
- ".gitignore"
|
205
235
|
- ".overcommit.yml"
|
206
236
|
- ".rspec"
|
@@ -208,6 +238,7 @@ files:
|
|
208
238
|
- ".rubocop.yml"
|
209
239
|
- ".ruby-gemset"
|
210
240
|
- ".ruby-version"
|
241
|
+
- CHANGELOG.md
|
211
242
|
- Gemfile
|
212
243
|
- Guardfile
|
213
244
|
- README.md
|
@@ -231,15 +262,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
262
|
requirements:
|
232
263
|
- - ">="
|
233
264
|
- !ruby/object:Gem::Version
|
234
|
-
version: 2.
|
265
|
+
version: 2.5.8
|
235
266
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
267
|
requirements:
|
237
268
|
- - ">="
|
238
269
|
- !ruby/object:Gem::Version
|
239
270
|
version: '0'
|
240
271
|
requirements: []
|
241
|
-
|
242
|
-
rubygems_version: 2.7.8
|
272
|
+
rubygems_version: 3.2.3
|
243
273
|
signing_key:
|
244
274
|
specification_version: 4
|
245
275
|
summary: This gem is here to help DRYing your tests cases by giving a better "shared_examples".
|
data/.circleci/config.yml
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# Ruby CircleCI 2.0 configuration file
|
2
|
-
#
|
3
|
-
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
-
#
|
5
|
-
version: 2
|
6
|
-
jobs:
|
7
|
-
build:
|
8
|
-
working_directory: ~/app
|
9
|
-
docker:
|
10
|
-
- image: circleci/ruby:2.5.3-node
|
11
|
-
environment:
|
12
|
-
|
13
|
-
steps:
|
14
|
-
- checkout
|
15
|
-
|
16
|
-
- run:
|
17
|
-
name: install dependencies
|
18
|
-
command: |
|
19
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
20
|
-
|
21
|
-
- run:
|
22
|
-
name: run linting
|
23
|
-
command: |
|
24
|
-
git config --global user.email $CIRCLE_USERNAME@none.com && \
|
25
|
-
git config --global user.name "$CIRCLE_USERNAME @$CIRCLE_PROJECT_REPONAME" && \
|
26
|
-
bundle exec overcommit --sign && \
|
27
|
-
bundle exec overcommit --run
|
28
|
-
# run tests!
|
29
|
-
- run:
|
30
|
-
name: run tests
|
31
|
-
command: |
|
32
|
-
mkdir /tmp/test-results
|
33
|
-
COVERAGE=true bundle exec rspec --format progress \
|
34
|
-
--format RspecJunitFormatter \
|
35
|
-
--out /tmp/test-results/rspec.xml \
|
36
|
-
--format progress
|
37
|
-
|
38
|
-
# collect reports
|
39
|
-
- store_test_results:
|
40
|
-
path: /tmp/test-results
|
41
|
-
- store_artifacts:
|
42
|
-
path: /tmp/test-results
|
43
|
-
destination: test-results
|
44
|
-
- store_artifacts:
|
45
|
-
path: ~/app/coverage
|
46
|
-
destination: coverage-results
|
47
|
-
deploy:
|
48
|
-
working_directory: ~/app
|
49
|
-
docker:
|
50
|
-
- image: circleci/ruby:2.5.3-node
|
51
|
-
environment:
|
52
|
-
|
53
|
-
steps:
|
54
|
-
- checkout
|
55
|
-
|
56
|
-
- run:
|
57
|
-
name: install dependencies
|
58
|
-
command: |
|
59
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
60
|
-
|
61
|
-
- run:
|
62
|
-
name: Setup Rubygems
|
63
|
-
command: bash .circleci/setup-rubygems.sh
|
64
|
-
|
65
|
-
- run:
|
66
|
-
name: Publish new version of the gem
|
67
|
-
command: |
|
68
|
-
git config --global user.email denis.pasin+circleci@gmail.com && \
|
69
|
-
git config --global user.name "Denis <CircleCI> Pasin" && \
|
70
|
-
rake release
|
71
|
-
workflows:
|
72
|
-
version: 2
|
73
|
-
build-and-deploy:
|
74
|
-
jobs:
|
75
|
-
- build
|
76
|
-
- deploy:
|
77
|
-
requires:
|
78
|
-
- build
|
79
|
-
filters:
|
80
|
-
branches:
|
81
|
-
only: master
|
data/.circleci/setup-rubygems.sh
DELETED