rspec3-action 2.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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +2 -0
- data/CHANGELOG +17 -0
- data/Gemfile +4 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/lib/rspec-action.rb +33 -0
- data/lib/rspec-action/version.rb +5 -0
- data/rspec-action.gemspec +25 -0
- data/spec/lib/rspec-action_spec.rb +77 -0
- data/spec/spec_helper.rb +1 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96d4a863bf318107028f8eaf6637a95d888563cf
|
4
|
+
data.tar.gz: fab1e6dc481309a216f8fbdf16852c175628a12d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6619f5053779af51d22727059ff36b52a81ffb90b151cf7229b99af0456534bf01dedd0fb2fea0e9682a556f26e0dd4cfac73db8e2fb143946df66f086f66d96
|
7
|
+
data.tar.gz: 62095f64f149eeabe74fb943b925c11c0bb17ec9f35d433142ca520a6f7b8b2abaadafb7b63f8bcca1d8801b3210c64f2b340403a3338fe55dc3324d9e7e7163
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#v2.0.0
|
2
|
+
* rspec 3 support, drop support for rspec 2.*
|
3
|
+
|
4
|
+
#v1.2.0
|
5
|
+
* rspec 2.13 support, drop support for rspec 2.12 or lower
|
6
|
+
|
7
|
+
|
8
|
+
#v1.1.0
|
9
|
+
* rspec 2.12 support, drop support for rspec 2.11 or lower
|
10
|
+
|
11
|
+
|
12
|
+
#v1.0.0
|
13
|
+
* rspec 2.11 support, tested with 2.0, 2.6, 2.11
|
14
|
+
|
15
|
+
|
16
|
+
#v0.0.1
|
17
|
+
* Initial release, works with rspec 2.6
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
[](http://travis-ci.org/#!/cutalion/rspec-action)
|
2
|
+
[](https://codeclimate.com/github/cutalion/rspec-action)
|
3
|
+
|
4
|
+
# rspec3-action
|
5
|
+
|
6
|
+
An extension to rspec, which provides an `action` command to rspec examples. Forked from rspec-action
|
7
|
+
|
8
|
+
# Description
|
9
|
+
|
10
|
+
rspec-action3 is an extension to rspec3, which allows you to specify the last before hook.
|
11
|
+
I named it `action`, because it's quite helpful for me in the controller specs.
|
12
|
+
|
13
|
+
*IMPORTANT*
|
14
|
+
Use rspec-action 1.2.0 for Rspec 2.13
|
15
|
+
|
16
|
+
Use rspec-action 1.1.0 for Rspec 2.12
|
17
|
+
|
18
|
+
Use rspec-action 1.0.0 for Rspec 2.11 or lower.
|
19
|
+
|
20
|
+
I prefer to write
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
describe "GET index" do
|
24
|
+
action { get :index }
|
25
|
+
|
26
|
+
context 'if user signed in' do
|
27
|
+
before { sign_in user }
|
28
|
+
it { should respond_with :success }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'if user signed out' do
|
32
|
+
it { should redirect_to sign_in_path }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
instead of
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
describe "GET index" do
|
41
|
+
context 'if user signed in' do
|
42
|
+
before { sign_in user }
|
43
|
+
before { get :index }
|
44
|
+
it { should respond_with :success }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'if user signed out' do
|
48
|
+
before { get :index }
|
49
|
+
it { should redirect_to sign_in_path }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
# Requirements
|
55
|
+
|
56
|
+
* [rspec3](https://github.com/rspec/rspec) ~> 3.0
|
57
|
+
|
58
|
+
# Installation
|
59
|
+
|
60
|
+
gem install rspec-action3
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/rspec-action.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rspec"
|
3
|
+
require "rspec-action/version"
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Core
|
7
|
+
module Hooks
|
8
|
+
def action(&block)
|
9
|
+
around do |ex|
|
10
|
+
self.class.hooks.send(:ensure_hooks_initialized_for, :before, :example)
|
11
|
+
self.class.remove_previous_action &block
|
12
|
+
self.class.before &block unless self.class.action_added?(&block)
|
13
|
+
self.class.hooks.send(:hooks_for, :before, :example)&.items_and_filters&.last&.instance_eval do
|
14
|
+
def action_hook?; true; end
|
15
|
+
end
|
16
|
+
ex.run
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_previous_action(&block)
|
21
|
+
parent_groups.each do |parent|
|
22
|
+
parent.hooks.send(:ensure_hooks_initialized_for, :before, :example)
|
23
|
+
parent.hooks.send(:hooks_for, :before, :example)&.items_and_filters&.delete_if {|hook| hook.respond_to?(:action_hook?)}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def action_added?(&block)
|
28
|
+
parent_groups_hooks = parent_groups.reverse.map { |parent| parent.hooks.send(:hooks_for, :before, :example)&.items_and_filters }.flatten
|
29
|
+
parent_groups_hooks.include? block
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rspec-action/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rspec3-action"
|
7
|
+
s.version = RSpec::Action::VERSION
|
8
|
+
s.authors = ["Alexander Glushkov", "Colin Ewen"]
|
9
|
+
s.email = ["cutalion@gmail.com", "colin@draecas.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Adds an "action" method to rspec examples}
|
12
|
+
s.description = %q{Adds an "action" method to rspec examples, which is a last "before" in fact }
|
13
|
+
s.required_ruby_version = '>= 2.3'
|
14
|
+
|
15
|
+
s.rubyforge_project = "rspec-action"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "rspec", ">= 3.0", "<4.0"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Core::Hooks do
|
4
|
+
def str; @str ||= ""; @str end
|
5
|
+
|
6
|
+
describe "simple example" do
|
7
|
+
before { str << "1" }
|
8
|
+
action { str << "3" }
|
9
|
+
before { str << "2" }
|
10
|
+
|
11
|
+
specify { str.should == "123" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "example with two expecations" do
|
15
|
+
before { str << "1" }
|
16
|
+
action { str << "3" }
|
17
|
+
before { str << "2" }
|
18
|
+
|
19
|
+
specify { str.should == "123" }
|
20
|
+
specify { str.should == "123" }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "two-level example" do
|
24
|
+
action { str << "3" }
|
25
|
+
context "level one" do
|
26
|
+
before { str << "1" }
|
27
|
+
before { str << "2" }
|
28
|
+
|
29
|
+
specify { str.should == "123" }
|
30
|
+
|
31
|
+
context "level two" do
|
32
|
+
before { str << "4" }
|
33
|
+
before { str << "5" }
|
34
|
+
|
35
|
+
specify { str.should == "12453" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "two examples" do
|
41
|
+
action { str << "3" }
|
42
|
+
context "first example" do
|
43
|
+
before { str << "1" }
|
44
|
+
before { str << "2" }
|
45
|
+
specify { str.should == "123" }
|
46
|
+
end
|
47
|
+
context "second example" do
|
48
|
+
before { str << "5" }
|
49
|
+
before { str << "4" }
|
50
|
+
specify { str.should == "543" }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "rewrite action" do
|
55
|
+
context "on the same level" do
|
56
|
+
before { str << "1" }
|
57
|
+
action { str << "3" }
|
58
|
+
action { str << "4" }
|
59
|
+
before { str << "2" }
|
60
|
+
|
61
|
+
specify { str.should == "124" }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "on the deeper level" do
|
65
|
+
before { str << "1" }
|
66
|
+
action { str << "3" }
|
67
|
+
before { str << "2" }
|
68
|
+
|
69
|
+
specify { str.should == "123" }
|
70
|
+
|
71
|
+
context "second level" do
|
72
|
+
action { str << "4" }
|
73
|
+
specify { str.should == "124" }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rspec-action"
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec3-action
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Glushkov
|
8
|
+
- Colin Ewen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '4.0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
description: 'Adds an "action" method to rspec examples, which is a last "before"
|
49
|
+
in fact '
|
50
|
+
email:
|
51
|
+
- cutalion@gmail.com
|
52
|
+
- colin@draecas.com
|
53
|
+
executables: []
|
54
|
+
extensions: []
|
55
|
+
extra_rdoc_files: []
|
56
|
+
files:
|
57
|
+
- ".gitignore"
|
58
|
+
- ".travis.yml"
|
59
|
+
- CHANGELOG
|
60
|
+
- Gemfile
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- lib/rspec-action.rb
|
64
|
+
- lib/rspec-action/version.rb
|
65
|
+
- rspec-action.gemspec
|
66
|
+
- spec/lib/rspec-action_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
homepage: ''
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '2.3'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project: rspec-action
|
87
|
+
rubygems_version: 2.6.13
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Adds an "action" method to rspec examples
|
91
|
+
test_files:
|
92
|
+
- spec/lib/rspec-action_spec.rb
|
93
|
+
- spec/spec_helper.rb
|