rspec-action 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm: 1.9.3
2
+ script: bundle exec rspec spec
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ #v0.0.1
2
+
3
+ * Initial release, works with rspec 2.6
4
+
5
+
6
+ #v1.0.0
7
+
8
+ * rspec 2.11 support, tested with 2.0, 2.6, 2.11
data/README.markdown CHANGED
@@ -1,3 +1,6 @@
1
+ [![Build Status](https://secure.travis-ci.org/cutalion/rspec-action.png)](http://travis-ci.org/#!/cutalion/rspec-action)
2
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/cutalion/rspec-action)
3
+
1
4
  # rspec-action
2
5
 
3
6
  An extension to rspec, which provides an `action` command to rspec examples
data/lib/rspec-action.rb CHANGED
@@ -1,14 +1,30 @@
1
+ require "rubygems"
2
+ require "rspec"
1
3
  require "rspec-action/version"
2
4
 
3
5
  module RSpec
4
6
  module Core
5
7
  module Hooks
6
8
  def action(&block)
7
- before { self.class.before(&block) unless self.class.action_added?(&block) }
9
+ around do |ex|
10
+ self.class.remove_previous_action &block
11
+ self.class.before &block unless self.class.action_added?(&block)
12
+ self.class.hooks[:before][:each].last.instance_eval do
13
+ def action_hook?; true; end
14
+ end
15
+ ex.run
16
+ end
17
+ end
18
+
19
+ def remove_previous_action(&block)
20
+ ancestors.each do |ancestor|
21
+ ancestor.hooks[:before][:each].delete_if {|hook| hook.respond_to?(:action_hook?)}
22
+ end
8
23
  end
9
24
 
10
25
  def action_added?(&block)
11
- hooks[:before][:each].map(&:to_proc).include? block
26
+ ancestors_hooks = ancestors.reverse.map { |ancestor| ancestor.hooks[:before][:each] }.flatten
27
+ ancestors_hooks.map(&:to_proc).include? block
12
28
  end
13
29
  end
14
30
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Action
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
data/rspec-action.gemspec CHANGED
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_dependency "rspec", "~> 2.0"
22
+ s.add_development_dependency "rake"
22
23
  end
@@ -32,7 +32,7 @@ describe RSpec::Core::Hooks do
32
32
  before { str << "4" }
33
33
  before { str << "5" }
34
34
 
35
- specify { str.should == "123453" }
35
+ specify { str.should == "12453" }
36
36
  end
37
37
  end
38
38
  end
@@ -50,4 +50,28 @@ describe RSpec::Core::Hooks do
50
50
  specify { str.should == "543" }
51
51
  end
52
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
53
77
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-action
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 1
10
- version: 0.0.1
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Glushkov
@@ -15,12 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-15 00:00:00 Z
18
+ date: 2012-09-01 00:00:00 +03:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - ~>
@@ -30,8 +31,22 @@ dependencies:
30
31
  - 2
31
32
  - 0
32
33
  version: "2.0"
34
+ requirement: *id001
33
35
  type: :runtime
34
- version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ type: :development
35
50
  description: "Adds an \"action\" method to rspec examples, which is a last \"before\" in fact "
36
51
  email:
37
52
  - cutalion@gmail.com
@@ -43,6 +58,8 @@ extra_rdoc_files: []
43
58
 
44
59
  files:
45
60
  - .gitignore
61
+ - .travis.yml
62
+ - CHANGELOG
46
63
  - Gemfile
47
64
  - README.markdown
48
65
  - Rakefile
@@ -51,6 +68,7 @@ files:
51
68
  - rspec-action.gemspec
52
69
  - spec/lib/rspec-action_spec.rb
53
70
  - spec/spec_helper.rb
71
+ has_rdoc: true
54
72
  homepage: ""
55
73
  licenses: []
56
74
 
@@ -80,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
98
  requirements: []
81
99
 
82
100
  rubyforge_project: rspec-action
83
- rubygems_version: 1.8.6
101
+ rubygems_version: 1.4.2
84
102
  signing_key:
85
103
  specification_version: 3
86
104
  summary: Adds an "action" method to rspec examples