rspec-action 0.0.1
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/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.markdown +46 -0
- data/Rakefile +1 -0
- data/lib/rspec-action.rb +15 -0
- data/lib/rspec-action/version.rb +5 -0
- data/rspec-action.gemspec +22 -0
- data/spec/lib/rspec-action_spec.rb +53 -0
- data/spec/spec_helper.rb +1 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# rspec-action
|
2
|
+
|
3
|
+
An extension to rspec, which provides an `action` command to rspec examples
|
4
|
+
|
5
|
+
# Description
|
6
|
+
|
7
|
+
rspec-action is an extension to rspec2, which allows you to specify the last before hook.
|
8
|
+
I named it `action`, because it's quite helpful for me in the controller specs.
|
9
|
+
|
10
|
+
I prefer to write
|
11
|
+
|
12
|
+
describe "GET index" do
|
13
|
+
action { get :index }
|
14
|
+
|
15
|
+
context 'if user signed in' do
|
16
|
+
before { sign_in user }
|
17
|
+
it { should respond_with :success }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'if user signed out' do
|
21
|
+
it { should redirect_to sign_in_path }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
instead of
|
26
|
+
|
27
|
+
describe "GET index" do
|
28
|
+
context 'if user signed in' do
|
29
|
+
before { sign_in user }
|
30
|
+
before { get :index }
|
31
|
+
it { should respond_with :success }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'if user signed out' do
|
35
|
+
before { get :index }
|
36
|
+
it { should redirect_to sign_in_path }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Requirements
|
41
|
+
|
42
|
+
* [rspec2](https://github.com/rspec/rspec) ~> 2.0
|
43
|
+
|
44
|
+
# Installation
|
45
|
+
|
46
|
+
gem install rspec-action
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/rspec-action.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rspec-action/version"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
module Hooks
|
6
|
+
def action(&block)
|
7
|
+
before { self.class.before(&block) unless self.class.action_added?(&block) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def action_added?(&block)
|
11
|
+
hooks[:before][:each].map(&:to_proc).include? block
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 = "rspec-action"
|
7
|
+
s.version = RSpec::Action::VERSION
|
8
|
+
s.authors = ["Alexander Glushkov"]
|
9
|
+
s.email = ["cutalion@gmail.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
|
+
|
14
|
+
s.rubyforge_project = "rspec-action"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "rspec", "~> 2.0"
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 == "123453" }
|
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
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rspec-action"
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-action
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alexander Glushkov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-15 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: "2.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: "Adds an \"action\" method to rspec examples, which is a last \"before\" in fact "
|
36
|
+
email:
|
37
|
+
- cutalion@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.markdown
|
48
|
+
- Rakefile
|
49
|
+
- lib/rspec-action.rb
|
50
|
+
- lib/rspec-action/version.rb
|
51
|
+
- rspec-action.gemspec
|
52
|
+
- spec/lib/rspec-action_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: ""
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: rspec-action
|
83
|
+
rubygems_version: 1.8.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Adds an "action" method to rspec examples
|
87
|
+
test_files: []
|
88
|
+
|