dry_require_spec_helper 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0fe051bba9a604abfb0259e9238bd1beedc65d5
4
- data.tar.gz: 5d0aeae2eadd6c28a7027b4bd36eff6a52e801b0
3
+ metadata.gz: c794679c98c196d6591fb5b886d4c1c8c14ba491
4
+ data.tar.gz: 459f4762f8694d832543ba83274d4ec728849c5f
5
5
  SHA512:
6
- metadata.gz: 0aa8df9939b047941459d7b41740399a9dacd7fe78b6fd2c6c00ebc9488d3b40e270bcdc20da2b9a933bbd712d3f7564f3973f646475ff32ef7c6fba44b31c3c
7
- data.tar.gz: a442d6382a9ce134c72903e8429be11627c94daa1fc61f8e89d42dbd3cf13cb9da706e62160e0ca1bfe8b075dcaf45343e0994e7186b901cfcc8670f5466d9fa
6
+ metadata.gz: 93f2f17039d3257fc7ccbbe90c5603c22046e1e4312130f23d99395b1e72737bd0592a2d0f6ebe73f589ecbc25d609d7e82cb48d0411e85ba5a5e04e2a0caef3
7
+ data.tar.gz: 7ec4976d5334a56caba276e8a93f1ca5410d41e9fc8d990a49a253f61eaa929425ebb39461b60b4842de0ce0dadb61e4e57fba46ccd367feb6401996fda98f17
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dry_require_spec_helper [![Gem Version](https://badge.fury.io/rb/dry_require_spec_helper.svg)](http://badge.fury.io/rb/dry_require_spec_helper)
1
+ # dry_require_spec_helper [![Build Status](https://travis-ci.org/koic/dry_require_spec_helper.svg)](https://travis-ci.org/koic/dry_require_spec_helper) [![Gem Version](https://badge.fury.io/rb/dry_require_spec_helper.svg)](http://badge.fury.io/rb/dry_require_spec_helper)
2
2
 
3
3
  DRY (Don't Repeat Yourself) of `require 'spec_helper'`.
4
4
 
@@ -1,28 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- unless File.exist?('.rspec')
4
- puts 'dry_require_spec_helper: .rspec: No such file or directory'
3
+ require 'dry_require_spec_helper'
5
4
 
6
- exit 1
7
- end
8
-
9
- helper_name = if File.exists?('spec/rails_helper.rb') &&
10
- File.exist?('Gemfile.lock') &&
11
- File.read('Gemfile.lock').split("\n").detect {|gem| /rspec-rails \((\d)\.(\d)\.(\d)([0-9A-Za-z-]*)\)\z/ === gem } &&
12
- $1.to_i >= 3
13
- 'rails_helper'
14
- else
15
- 'spec_helper'
16
- end
17
-
18
- File.open('.rspec', 'a') {|file| file.write("--require #{helper_name}\n") }
19
-
20
- Dir['./spec/**/*_spec.rb'].each do |path|
21
- source = File.read(path)
22
-
23
- next unless /require +('(spec|rails)_helper'|"(spec|rails)_helper")\n*/ === source
24
-
25
- source.gsub!($&, '')
26
-
27
- File.open(path, 'w+') {|f| f.write(source) }
28
- end
5
+ DryRequireSpecHelper.dry('.')
@@ -0,0 +1,42 @@
1
+ require 'pathname'
2
+
3
+ module DryRequireSpecHelper
4
+ class Core
5
+ def initialize(target_path)
6
+ @target = Pathname(target_path)
7
+ end
8
+
9
+ def append_require_options
10
+ helper_name = used_rails_helper? ? 'rails_helper' : 'spec_helper'
11
+
12
+ if File.exist?(@target.join('.rspec'))
13
+ lines = File.read(@target.join('.rspec'))
14
+
15
+ return if lines.split("\n").detect {|line| /--require +#{helper_name}/ === line }
16
+ end
17
+
18
+ File.open(@target.join('.rspec'), 'a') {|file| file.write("--require #{helper_name}\n") }
19
+ end
20
+
21
+ def remove_require_spec_helper
22
+ Dir[@target.join('spec/**/*_spec.rb')].each do |path|
23
+ source = File.read(path)
24
+
25
+ next unless /require +('(spec|rails)_helper'|"(spec|rails)_helper")\n*/ === source
26
+
27
+ source.gsub!($&, '')
28
+
29
+ File.open(path, 'w+') {|f| f.write(source) }
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def used_rails_helper?
36
+ File.exists?(@target.join('spec/rails_helper.rb')) &&
37
+ File.exist?(@target.join('Gemfile.lock')) &&
38
+ File.read(@target.join('Gemfile.lock')).split("\n").detect {|gem| /rspec-rails \((\d)\.(\d)\.(\d)([0-9A-Za-z-]*)\)\z/ === gem } &&
39
+ $1.to_i >= 3
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module DryRequireSpecHelper
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -1 +1,12 @@
1
- module DryRequireSpecHelper; end
1
+ require 'dry_require_spec_helper/core'
2
+
3
+ module DryRequireSpecHelper
4
+ def dry(target_path)
5
+ core = Core.new(target_path)
6
+
7
+ core.append_require_options
8
+ core.remove_require_spec_helper
9
+ end
10
+
11
+ module_function :dry
12
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry_require_spec_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
13
27
  description: DRY (Don't Repeat Yourself) of require 'spec_helper'.
14
28
  email: koic.ito@gmail.com
15
29
  executables:
@@ -21,6 +35,7 @@ files:
21
35
  - README.md
22
36
  - bin/dry_require_spec_helper
23
37
  - lib/dry_require_spec_helper.rb
38
+ - lib/dry_require_spec_helper/core.rb
24
39
  - lib/dry_require_spec_helper/version.rb
25
40
  homepage: http://github.com/koic/dry_require_spec_helper
26
41
  licenses: