rspec-do_action 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4fbf8d9de226328d8aa35ef6881a6b69f05b80e2
4
+ data.tar.gz: 7dbeb5e5c50229518a9fad157fcb4152a891b3f7
5
+ SHA512:
6
+ metadata.gz: 9305e493cf551042b9797cd08a42bf9633d0fbf326061184f92bab9ff1453bf5428f6cccf1b5eab907e0f1f4d5a47a29ff74c374cb3118ee55b9de433dfe6a03
7
+ data.tar.gz: 8b335fe15b59c7d176e4b6cdc240ed124b8957473bcf7b2be3eb912c2ae46594fc042687a7ee36f725f41dda180bb45ab5c9e1d84bb51d9fc72be24aa5d578cb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ script: "bundle exec rake spec"
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ gemfile:
7
+ - Gemfile
8
+ - gemfiles/rspec3.gemfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-do_action.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 sunteya
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Rspec::DoAction [![Build Status](https://travis-ci.org/sunteya/rspec-do_action.png?branch=master)](https://travis-ci.org/sunteya/rspec-do_action)
2
+
3
+ add 'acton' and some useful methods for rspec one-liner syntax.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rspec-do_action'
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ describe "invoke 'do_action' automatically" do
15
+ subject(:result) { [] }
16
+ action { result << 2 } # will invoke after all before hook run finished
17
+ before { result << 1 }
18
+ it { should eq [ 1, 2 ] }
19
+ end
20
+
21
+ describe "explicit invoke 'do_action'" do
22
+ subject(:result) { [] }
23
+ action { result << 2 }
24
+ before { result << 1 }
25
+ do_action
26
+ before { result << 3 }
27
+
28
+ it { should eq [ 1, 2, 3 ] }
29
+ end
30
+
31
+ describe "skip auto 'do_action' invoke" do
32
+ action { raise RuntimeError }
33
+ skip_do_action
34
+
35
+ it { expect{ do_action }.to raise_error }
36
+ end
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( http://github.com/sunteya/rspec-do_action/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rspec", "3.0.0.beta1"
4
+
5
+ # Specify your gem's dependencies in rspec-do_action.gemspec
6
+ gemspec path: '..'
@@ -0,0 +1,62 @@
1
+ require "rspec"
2
+ require "rspec-do_action/version"
3
+
4
+ module Rspec
5
+ module DoAction
6
+
7
+ module InstanceMethods
8
+ def do_action
9
+ expect(action).to_not be_nil, "need define action block"
10
+ instance_eval &action
11
+ end
12
+
13
+ def auto_do_action_once(force = false)
14
+ return if find_variable("@skip_do_action")
15
+ return if !force && action.nil?
16
+
17
+ if !@auto_do_action_once
18
+ do_action
19
+ @auto_do_action_once = true
20
+ end
21
+ end
22
+
23
+ def action
24
+ find_variable("@action")
25
+ end
26
+
27
+ def find_variable(name)
28
+ group = self.class.parent_groups.find { |group| group.instance_variable_defined?(name) }
29
+ group.instance_variable_get(name) if group
30
+ end
31
+ end
32
+
33
+ module ClassMethods
34
+ def action(&block)
35
+ @action = block
36
+ end
37
+
38
+ def do_action(&block)
39
+ action(&block) if block
40
+ before { auto_do_action_once(true) }
41
+ end
42
+
43
+ def skip_do_action
44
+ @skip_do_action = true
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ class RSpec::Core::Example
51
+ def run_before_each_with_action
52
+ run_before_each_without_action
53
+ example_group_instance.send(:auto_do_action_once)
54
+ end
55
+ alias_method :run_before_each_without_action, :run_before_each
56
+ alias_method :run_before_each, :run_before_each_with_action
57
+ end
58
+
59
+ RSpec.configure do |config|
60
+ config.include Rspec::DoAction::InstanceMethods
61
+ config.extend Rspec::DoAction::ClassMethods
62
+ end
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module DoAction
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec-do_action/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-do_action"
8
+ spec.version = Rspec::DoAction::VERSION
9
+ spec.authors = ["sunteya"]
10
+ spec.email = ["sunteya@gmail.com"]
11
+ spec.summary = %q{add 'acton' and some useful methods for rspec one-liner syntax.}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry-nav"
25
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe "Readme Usage" do
4
+ README_PATH = File.expand_path("../../../README.md", __FILE__)
5
+
6
+ def self.extract_usage_rspec
7
+ lines = File.read(README_PATH).lines.to_a
8
+ lineno = lines.index { |line| line =~ /^```ruby/ } + 1
9
+ length = lines[lineno, lines.length].index { |line| line =~ /^```/ }
10
+ [ lines[lineno, length].join, README_PATH, lineno ]
11
+ end
12
+
13
+ instance_eval *extract_usage_rspec
14
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe Rspec::DoAction do
4
+ subject(:result) { [] }
5
+
6
+ describe "auto invoke after hooks" do
7
+ before { result << 0 }
8
+ action { result << 2 }
9
+ before { result << 1 }
10
+ it { should eq [ 0, 1, 2 ] }
11
+ end
12
+
13
+ describe "explicit invoke should before hooks" do
14
+ do_action { result << 2 }
15
+ before { result << 3 }
16
+ it { should eq [ 2, 3 ] }
17
+ end
18
+
19
+ describe "nested example" do
20
+ action { result << 2 }
21
+
22
+ context "with override define" do
23
+ action { result << 0 }
24
+ it { should eq [ 0 ] }
25
+ end
26
+
27
+ context "with hooks" do
28
+ before { result << 1 }
29
+ it { should eq [ 1 , 2 ] }
30
+ end
31
+ end
32
+
33
+ describe "skip_do_action" do
34
+ action { result << 2 }
35
+ before { result << 1 }
36
+ it { should eq [ 1, 2 ] }
37
+
38
+ context "with nested example" do
39
+ skip_do_action
40
+ it { should eq [ 1 ] }
41
+ end
42
+
43
+ context "when invoke in example" do
44
+ skip_do_action
45
+ it { do_action; should eq [ 1, 2 ] }
46
+ end
47
+ end
48
+
49
+ describe "other rspec without action" do
50
+ before { result << 1 }
51
+ it { should eq [ 1 ] }
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ require "rspec-do_action"
2
+ require "pry-nav"
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true if RSpec::Version::STRING =~ /^2/
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ config.order = 'random'
9
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-do_action
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - sunteya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-nav
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: add 'acton' and some useful methods for rspec one-liner syntax.
70
+ email:
71
+ - sunteya@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - gemfiles/rspec3.gemfile
84
+ - lib/rspec-do_action.rb
85
+ - lib/rspec-do_action/version.rb
86
+ - rspec-do_action.gemspec
87
+ - spec/lib/redmine_usage_spec.rb
88
+ - spec/lib/rspec-do_action_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: add 'acton' and some useful methods for rspec one-liner syntax.
114
+ test_files:
115
+ - spec/lib/redmine_usage_spec.rb
116
+ - spec/lib/rspec-do_action_spec.rb
117
+ - spec/spec_helper.rb