pork-rspec 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b9bc43762097da7f0733b0ca949710ecddc3fe0
4
+ data.tar.gz: 2cd826a3fe751321d56980ca03c83694d85b8e1d
5
+ SHA512:
6
+ metadata.gz: bac2f7cd6c127c85d53426ca477b37208247f93a357a70247dd69faec30b88a297bef09f4eddbc14a009a974259bc6840190f4b66c30945fde8dd2b9c86e6b17
7
+ data.tar.gz: 98caf073fdb35d8c86e538157ddf380e8631c780016da5cf67a5b758c10c66e56afa09bb29eb046b40910799ceb245ffd16d670eb0d4af2e1c8eec97d2b2d45b
@@ -0,0 +1,2 @@
1
+ /pkg/
2
+ /coverage/
@@ -0,0 +1,6 @@
1
+ [submodule "pork"]
2
+ path = pork
3
+ url = git://github.com/godfat/pork.git
4
+ [submodule "task"]
5
+ path = task
6
+ url = git://github.com/godfat/gemgem
@@ -0,0 +1,18 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ - 2.3.1
6
+ - rbx
7
+ - jruby-9
8
+
9
+ before_install:
10
+ - rvm get head
11
+ - rvm reload
12
+ - rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
13
+ install: 'gem install bundler; bundle install --retry=3'
14
+ script: 'ruby -r bundler/setup -S rake test'
15
+
16
+ env:
17
+ - PORK=1
18
+ - RSPEC=1
@@ -0,0 +1,5 @@
1
+ # CHANGES
2
+
3
+ ## pork-rspec 0.5.0 -- 2016-09-14
4
+
5
+ * Birthday! Not everything is implemented, but it's very usable now.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'rspec'
8
+
9
+ gem 'simplecov', :require => false if ENV['COV']
10
+ gem 'coveralls', :require => false if ENV['CI']
11
+
12
+ platform :rbx do
13
+ gem 'rubysl-singleton' # used in rake
14
+ end
@@ -0,0 +1,41 @@
1
+ # pork-rspec [![Build Status](https://secure.travis-ci.org/godfat/pork-rspec.png?branch=master)](http://travis-ci.org/godfat/pork-rspec) [![Coverage Status](https://coveralls.io/repos/godfat/pork-rspec/badge.png)](https://coveralls.io/r/godfat/pork-rspec) [![Join the chat at https://gitter.im/godfat/pork-rspec](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/pork-rspec)
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/pork-rspec)
8
+ * [rubygems](https://rubygems.org/gems/pork-rspec)
9
+ * [rdoc](http://rdoc.info/github/godfat/pork-rspec)
10
+
11
+ ## DESCRIPTION:
12
+
13
+ RSpec compatibility layer for Pork.
14
+
15
+ ## WHY?
16
+
17
+ * So people could see how to extend Pork easily.
18
+ * Perhaps then it would be easier to adopt Pork.
19
+ * Because why not? :P
20
+
21
+ ## CONTRIBUTORS:
22
+
23
+ * Lin Jen-Shin (@godfat)
24
+
25
+ ## LICENSE:
26
+
27
+ Apache License 2.0
28
+
29
+ Copyright (c) 2016, Lin Jen-Shin (godfat)
30
+
31
+ Licensed under the Apache License, Version 2.0 (the "License");
32
+ you may not use this file except in compliance with the License.
33
+ You may obtain a copy of the License at
34
+
35
+ <http://www.apache.org/licenses/LICENSE-2.0>
36
+
37
+ Unless required by applicable law or agreed to in writing, software
38
+ distributed under the License is distributed on an "AS IS" BASIS,
39
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ See the License for the specific language governing permissions and
41
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+
2
+ begin
3
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
4
+ rescue LoadError
5
+ sh 'git submodule update --init --recursive'
6
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
+ end
8
+
9
+ %w[lib pork/lib].each do |path|
10
+ $LOAD_PATH.unshift(File.expand_path("#{dir}/#{path}"))
11
+ end
12
+
13
+ Gemgem.init(dir) do |s|
14
+ s.name = 'pork-rspec'
15
+ s.version = '0.5.0'
16
+
17
+ %w[pork muack].each{ |g| s.add_runtime_dependency(g) }
18
+
19
+ # exclude pork
20
+ s.files.reject!{ |f| f.start_with?('pork/') }
21
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'pork/auto'
3
+ require 'pork-rspec/config'
4
+ require 'pork-rspec/suite'
5
+ require 'pork-rspec/context'
6
+ require 'pork-rspec/mock'
7
+
8
+ Pork::Suite.extend RSpec::Suite
9
+ Pork::Suite.include RSpec::Context
10
+ Pork::Suite.include RSpec::Mock
11
+ Pork::Suite.after do
12
+ Muack.verify
13
+ end
14
+
15
+ module RSpec
16
+ include Pork::API
17
+ public *private_instance_methods
18
+ include Alias
19
+
20
+ def self.configure
21
+ yield(config)
22
+ end
23
+
24
+ def self.config
25
+ @config ||= Config.new
26
+ end
27
+ end
28
+
29
+ include RSpec
@@ -0,0 +1,33 @@
1
+
2
+ module RSpec
3
+ module Alias
4
+ def it desc='', opts={}, &block
5
+ would(desc, opts, &block)
6
+ end
7
+
8
+ def it_behaves_like desc='', *args, &block
9
+ copy(desc) do
10
+ describe(desc, *args, &block)
11
+ end
12
+ end
13
+
14
+ def self.included mod
15
+ Alias.add(mod,
16
+ %i[it example specify],
17
+ %i[describe context example_group],
18
+ %i[copy shared_examples shared_context],
19
+ %i[paste include_examples include_context
20
+ it_behaves_like it_should_behave_like])
21
+ end
22
+
23
+ def self.add mod, *names
24
+ mod.module_eval do
25
+ names.each do |(old, *news)|
26
+ news.each do |name|
27
+ alias_method name, old
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+
2
+ module RSpec
3
+ class Config < Struct.new(:modules)
4
+ def initialize
5
+ super([])
6
+ end
7
+
8
+ def include mod, *args
9
+ modules << mod
10
+ warn("Ignored include arguments: #{args}") if args.any?
11
+ end
12
+
13
+ def before *types
14
+ end
15
+
16
+ def after *types
17
+ end
18
+
19
+ def around *types, &block
20
+ before(*types, &block)
21
+ after(*types, &block)
22
+ end
23
+
24
+ def method_missing msg, *args
25
+ warn("Unrecognized configuration: #{msg}(*#{args})")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,98 @@
1
+
2
+ require 'pork-rspec/expect'
3
+
4
+ module RSpec
5
+ module Context
6
+ def described_class klass=self.class, desc=klass.desc
7
+ case current = klass.desc
8
+ when Module
9
+ current
10
+ else
11
+ if parent = klass.instance_variable_get(:@super_executor)
12
+ described_class(parent, desc)
13
+ else
14
+ desc
15
+ end
16
+ end
17
+ end
18
+
19
+ def subject
20
+ @subject ||= case klass = described_class
21
+ when Class
22
+ klass.new
23
+ else
24
+ klass
25
+ end
26
+ end
27
+
28
+ def is_expected
29
+ expect(subject)
30
+ end
31
+
32
+ def expect obj=self, &block
33
+ Expect.new(pork_stat, block || obj)
34
+ end
35
+
36
+ def eq rhs
37
+ ->(actual){ actual == rhs }
38
+ end
39
+
40
+ def eql rhs
41
+ ->(actual){ actual.eql?(rhs) }
42
+ end
43
+
44
+ def equal rhs
45
+ ->(actual){ actual.equal?(rhs) }
46
+ end
47
+ alias_method :be, :equal
48
+
49
+ def be_an_instance_of rhs
50
+ ->(actual){ actual.class == rhs }
51
+ end
52
+
53
+ def be_a rhs
54
+ ->(actual){ actual.kind_of?(rhs) }
55
+ end
56
+ alias_method :be_an, :be_a
57
+ alias_method :be_a_kind_of, :be_a
58
+
59
+ def be_truthy
60
+ ->(actual){ actual != nil && actual != false }
61
+ end
62
+
63
+ def be_falsey
64
+ :!.to_proc
65
+ end
66
+
67
+ def be_empty
68
+ :empty?.to_proc
69
+ end
70
+
71
+ def be_nil
72
+ eq(nil)
73
+ end
74
+
75
+ def raise_error error, msg=nil
76
+ ->(actual) do
77
+ exc = actual.raise(error)
78
+ expect(exc.message).to eq(msg) if msg
79
+ end
80
+ end
81
+
82
+ def contain_exactly *elements
83
+ eq(elements)
84
+ end
85
+
86
+ def match_array array
87
+ eq(array)
88
+ end
89
+
90
+ def match rhs
91
+ ->(actual){ actual =~ rhs }
92
+ end
93
+
94
+ def start_with str
95
+ ->(actual){ actual.start_with?(str) }
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,41 @@
1
+
2
+ require 'pork/expect'
3
+ require 'pork-rspec/mock'
4
+
5
+ module RSpec
6
+ class Expect < Struct.new(:pork_stat, :object)
7
+ def to verifier, negate=false
8
+ case verifier
9
+ when Array, Mock::Receive
10
+ mock(verifier)
11
+ else
12
+ expect = Pork::Expect.new(pork_stat, object)
13
+ expect.not if negate
14
+ verifier.call(expect)
15
+ end
16
+ end
17
+
18
+ def not_to verifier
19
+ to(verifier, true)
20
+ end
21
+ alias_method :to_not, :not_to
22
+
23
+ private
24
+ def mock receive
25
+ case receive
26
+ when Array
27
+ receive.each(&method(:stub))
28
+ else
29
+ stub(receive)
30
+ end
31
+
32
+ object
33
+ end
34
+
35
+ def stub receive
36
+ receive.blocks.each do |block|
37
+ Muack::API.mock(object).method_missing(receive.message, &block)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,55 @@
1
+
2
+ require 'muack'
3
+
4
+ module RSpec
5
+ module Mock
6
+ class Allow < Struct.new(:object)
7
+ def to receive
8
+ case receive
9
+ when Array
10
+ receive.each(&method(:stub))
11
+ else
12
+ stub(receive)
13
+ end
14
+
15
+ object
16
+ end
17
+
18
+ private
19
+ def stub receive
20
+ Muack::API.stub(object). # not sure why rspec picked this behaviour
21
+ method_missing(receive.message, &receive.blocks.last)
22
+
23
+ receive.blocks[0..-2].each do |block|
24
+ Muack::API.coat(object).method_missing(receive.message, &block)
25
+ end
26
+ end
27
+ end
28
+
29
+ class Receive < Struct.new(:message, :blocks)
30
+ def and_return *values
31
+ self.blocks = values.map{ |v| lambda{ v } }
32
+ self
33
+ end
34
+ end
35
+
36
+ def double name='unnamed', defs={}
37
+ defs = name if name.kind_of?(Hash)
38
+ allow(Object.new).to receive_messages(defs)
39
+ end
40
+
41
+ def allow obj
42
+ Allow.new(obj)
43
+ end
44
+
45
+ def receive msg, &block
46
+ Receive.new(msg, [block])
47
+ end
48
+
49
+ def receive_messages defs
50
+ defs.map do |msg, value|
51
+ receive(msg).and_return(value)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+
2
+ require 'pork'
3
+ require 'pork-rspec/alias'
4
+
5
+ module RSpec
6
+ module Suite
7
+ include Pork::Suite::Imp
8
+ include Alias
9
+
10
+ def before *types
11
+ super()
12
+ warn("Ignored before arguments: #{types}") if types.any?
13
+ end
14
+
15
+ def after *types
16
+ super()
17
+ warn("Ignored after arguments: #{types}") if types.any?
18
+ end
19
+
20
+ def let name, &block
21
+ define_method(name) do
22
+ ivar = "@#{name}"
23
+ instance_variable_get(ivar) ||
24
+ instance_variable_set(ivar, instance_eval(&block))
25
+ end
26
+ end
27
+ alias_method :given, :let
28
+
29
+ def let! name, &block
30
+ let(name, &block)
31
+ before{ __send__(name) }
32
+ end
33
+
34
+ def subject &block
35
+ let(:subject, &block)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,52 @@
1
+
2
+ if ENV['RSPEC']
3
+ require 'rspec/autorun'
4
+ else
5
+ require 'pork-rspec'
6
+ end
7
+
8
+ module M
9
+ def m
10
+ 'm'
11
+ end
12
+
13
+ module N
14
+ def n
15
+ 'n'
16
+ end
17
+ end
18
+
19
+ module_function
20
+ def f
21
+ 'f'
22
+ end
23
+ end
24
+
25
+ class C
26
+ def self.c
27
+ 'C'
28
+ end
29
+ end
30
+
31
+ RSpec.configure do |config|
32
+ # config.use_transactional_fixtures = false
33
+ # config.use_instantiated_fixtures = false
34
+ config.mock_with :rspec
35
+
36
+ # config.verbose_retry = true
37
+ # config.display_try_failure_messages = true
38
+
39
+ config.include M, type: :controller
40
+ config.include M::N
41
+
42
+ # config.infer_spec_type_from_file_location!
43
+ config.raise_errors_for_deprecations!
44
+
45
+ config.before(:suite) do
46
+ # TODO
47
+ end
48
+
49
+ config.around(:each, :caching) do |example|
50
+ # TODO
51
+ end
52
+ end
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: pork-rspec 0.5.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "pork-rspec".freeze
6
+ s.version = "0.5.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
+ s.date = "2016-09-14"
12
+ s.description = "RSpec compatibility layer for Pork.".freeze
13
+ s.email = ["godfat (XD) godfat.org".freeze]
14
+ s.files = [
15
+ ".gitignore".freeze,
16
+ ".gitmodules".freeze,
17
+ ".travis.yml".freeze,
18
+ "CHANGES.md".freeze,
19
+ "Gemfile".freeze,
20
+ "README.md".freeze,
21
+ "Rakefile".freeze,
22
+ "lib/pork-rspec.rb".freeze,
23
+ "lib/pork-rspec/alias.rb".freeze,
24
+ "lib/pork-rspec/config.rb".freeze,
25
+ "lib/pork-rspec/context.rb".freeze,
26
+ "lib/pork-rspec/expect.rb".freeze,
27
+ "lib/pork-rspec/mock.rb".freeze,
28
+ "lib/pork-rspec/suite.rb".freeze,
29
+ "lib/pork-rspec/test.rb".freeze,
30
+ "pork-rspec.gemspec".freeze,
31
+ "task/README.md".freeze,
32
+ "task/gemgem.rb".freeze,
33
+ "test/test_context.rb".freeze,
34
+ "test/test_from_doc.rb".freeze,
35
+ "test/test_misc.rb".freeze,
36
+ "test/test_mock.rb".freeze]
37
+ s.homepage = "https://github.com/godfat/pork-rspec".freeze
38
+ s.licenses = ["Apache License 2.0".freeze]
39
+ s.rubygems_version = "2.6.6".freeze
40
+ s.summary = "RSpec compatibility layer for Pork.".freeze
41
+ s.test_files = [
42
+ "test/test_context.rb".freeze,
43
+ "test/test_from_doc.rb".freeze,
44
+ "test/test_misc.rb".freeze,
45
+ "test/test_mock.rb".freeze]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<pork>.freeze, [">= 0"])
52
+ s.add_runtime_dependency(%q<muack>.freeze, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<pork>.freeze, [">= 0"])
55
+ s.add_dependency(%q<muack>.freeze, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<pork>.freeze, [">= 0"])
59
+ s.add_dependency(%q<muack>.freeze, [">= 0"])
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ # Gemgem
2
+
3
+ ## DESCRIPTION:
4
+
5
+ Provided tasks:
6
+
7
+ rake clean # Remove ignored files
8
+ rake gem:build # Build gem
9
+ rake gem:install # Install gem
10
+ rake gem:release # Release gem
11
+ rake gem:spec # Generate gemspec
12
+ rake test # Run tests in memory
13
+
14
+ ## REQUIREMENTS:
15
+
16
+ * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
17
+
18
+ ## INSTALLATION:
19
+
20
+ git submodule add git://github.com/godfat/gemgem.git task
21
+
22
+ And in Rakefile:
23
+
24
+ ``` ruby
25
+ begin
26
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
27
+ rescue LoadError
28
+ sh 'git submodule update --init'
29
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
+ end
31
+
32
+ Gemgem.init(dir) do |s|
33
+ s.name = 'your-gem'
34
+ s.version = '0.1.0'
35
+ end
36
+ ```
37
+
38
+ ## LICENSE:
39
+
40
+ Apache License 2.0
41
+
42
+ Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
43
+
44
+ Licensed under the Apache License, Version 2.0 (the "License");
45
+ you may not use this file except in compliance with the License.
46
+ You may obtain a copy of the License at
47
+
48
+ <http://www.apache.org/licenses/LICENSE-2.0>
49
+
50
+ Unless required by applicable law or agreed to in writing, software
51
+ distributed under the License is distributed on an "AS IS" BASIS,
52
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53
+ See the License for the specific language governing permissions and
54
+ limitations under the License.
@@ -0,0 +1,316 @@
1
+
2
+ module Gemgem
3
+ class << self
4
+ attr_accessor :dir, :spec, :spec_create
5
+ end
6
+
7
+ module_function
8
+ def gem_tag ; "#{spec.name}-#{spec.version}" ; end
9
+ def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
10
+ def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
11
+ def pkg_dir ; "#{dir}/pkg" ; end
12
+ def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
+
14
+ def init dir, &block
15
+ self.dir = dir
16
+ $LOAD_PATH.unshift("#{dir}/lib")
17
+ ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
+ ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
19
+ self.spec_create = block
20
+ end
21
+
22
+ def create
23
+ spec = Gem::Specification.new do |s|
24
+ s.authors = ['Lin Jen-Shin (godfat)']
25
+ s.email = ['godfat (XD) godfat.org']
26
+
27
+ s.description = description.join
28
+ s.summary = description.first
29
+ s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
30
+
31
+ s.date = Time.now.strftime('%Y-%m-%d')
32
+ s.files = gem_files
33
+ s.test_files = test_files
34
+ s.executables = bin_files
35
+ end
36
+ spec_create.call(spec)
37
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
38
+ self.spec = spec
39
+ end
40
+
41
+ def gem_install
42
+ require 'rubygems/commands/install_command'
43
+ # read ~/.gemrc
44
+ Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
45
+ Gem::Command.extra_args = Gem.configuration[:gem]
46
+
47
+ # setup install options
48
+ cmd = Gem::Commands::InstallCommand.new
49
+ cmd.handle_options([])
50
+
51
+ # install
52
+ install = Gem::Installer.new(gem_path, cmd.options)
53
+ install.install
54
+ puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
55
+ end
56
+
57
+ def gem_spec
58
+ create
59
+ write
60
+ end
61
+
62
+ def gem_build
63
+ require 'fileutils'
64
+ require 'rubygems/package'
65
+ gem = nil
66
+ Dir.chdir(dir) do
67
+ gem = Gem::Package.build(Gem::Specification.load(spec_path))
68
+ FileUtils.mkdir_p(pkg_dir)
69
+ FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
70
+ end
71
+ puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
72
+ end
73
+
74
+ def gem_release
75
+ sh_git('tag', gem_tag)
76
+ sh_git('push')
77
+ sh_git('push', '--tags')
78
+ sh_gem('push', gem_path)
79
+ end
80
+
81
+ def gem_check
82
+ unless git('status', '--porcelain').empty?
83
+ puts("\e[35mWorking copy is not clean.\e[0m")
84
+ exit(3)
85
+ end
86
+
87
+ ver = spec.version.to_s
88
+
89
+ if ENV['VERSION'].nil?
90
+ puts("\e[35mExpected " \
91
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
92
+ exit(1)
93
+
94
+ elsif ENV['VERSION'] != ver
95
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
96
+ "\e[35mbut got\n " \
97
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
98
+ exit(2)
99
+ end
100
+ end
101
+
102
+ def test
103
+ return if test_files.empty?
104
+
105
+ if ENV['COV'] || ENV['CI']
106
+ require 'simplecov'
107
+ if ENV['CI']
108
+ begin
109
+ require 'coveralls'
110
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
111
+ rescue LoadError => e
112
+ puts "Cannot load coveralls, skip: #{e}"
113
+ end
114
+ end
115
+ SimpleCov.start do
116
+ add_filter('test/')
117
+ add_filter('test.rb')
118
+ end
119
+ end
120
+
121
+ test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
122
+ end
123
+
124
+ def clean
125
+ return if ignored_files.empty?
126
+
127
+ require 'fileutils'
128
+ trash = File.expand_path("~/.Trash/#{spec.name}")
129
+ puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
130
+
131
+ ignored_files.each do |file|
132
+ from = "#{dir}/#{file}"
133
+ to = "#{trash}/#{File.dirname(file)}"
134
+ puts strip_path(from)
135
+
136
+ FileUtils.mkdir_p(to)
137
+ FileUtils.mv(from, to)
138
+ end
139
+
140
+ print "\e[0m"
141
+ end
142
+
143
+ def write
144
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
145
+ end
146
+
147
+ def split_lines ruby
148
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
149
+ if $2.index(',')
150
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
151
+ else
152
+ s
153
+ end
154
+ }
155
+ end
156
+
157
+ def strip_path path
158
+ strip_home_path(strip_cwd_path(path))
159
+ end
160
+
161
+ def strip_home_path path
162
+ path.sub(ENV['HOME'], '~')
163
+ end
164
+
165
+ def strip_cwd_path path
166
+ path.sub(Dir.pwd, '.')
167
+ end
168
+
169
+ def git *args
170
+ `git --git-dir=#{dir}/.git #{args.join(' ')}`
171
+ end
172
+
173
+ def sh_git *args
174
+ Rake.sh('git', "--git-dir=#{dir}/.git", *args)
175
+ end
176
+
177
+ def sh_gem *args
178
+ Rake.sh(Gem.ruby, '-S', 'gem', *args)
179
+ end
180
+
181
+ def glob path=dir
182
+ Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
183
+ end
184
+
185
+ def readme
186
+ @readme ||=
187
+ if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
188
+ ps = "##{File.read(path)}".
189
+ scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
190
+ ps.inject('HEADER' => ps.first){ |r, s, i|
191
+ r[s[/\w+/]] = s
192
+ r
193
+ }
194
+ else
195
+ {}
196
+ end
197
+ end
198
+
199
+ def description
200
+ # JRuby String#lines is returning an enumerator
201
+ @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
202
+ end
203
+
204
+ def all_files
205
+ @all_files ||= fold_files(glob).sort
206
+ end
207
+
208
+ def fold_files files
209
+ files.inject([]){ |r, path|
210
+ if File.file?(path) && path !~ %r{/\.git(/|$)} &&
211
+ (rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
212
+ r << rpath
213
+ elsif File.symlink?(path) # walk into symlinks...
214
+ r.concat(fold_files(glob(File.expand_path(path,
215
+ File.readlink(path)))))
216
+ else
217
+ r
218
+ end
219
+ }
220
+ end
221
+
222
+ def gem_files
223
+ @gem_files ||= all_files.reject{ |f|
224
+ f =~ ignored_pattern && !git_files.include?(f)
225
+ }
226
+ end
227
+
228
+ def test_files
229
+ @test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
230
+ end
231
+
232
+ def bin_files
233
+ @bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
234
+ end
235
+
236
+ def git_files
237
+ @git_files ||= if File.exist?("#{dir}/.git")
238
+ git('ls-files').split("\n")
239
+ else
240
+ []
241
+ end
242
+ end
243
+
244
+ def ignored_files
245
+ @ignored_files ||= all_files.grep(ignored_pattern)
246
+ end
247
+
248
+ def ignored_pattern
249
+ @ignored_pattern ||= if gitignore.empty?
250
+ /^$/
251
+ else
252
+ Regexp.new(expand_patterns(gitignore).join('|'))
253
+ end
254
+ end
255
+
256
+ def expand_patterns pathes
257
+ # http://git-scm.com/docs/gitignore
258
+ pathes.flat_map{ |path|
259
+ # we didn't implement negative pattern for now
260
+ Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
261
+ }
262
+ end
263
+
264
+ def gitignore
265
+ @gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
266
+ File.read(path).lines.
267
+ reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
268
+ else
269
+ []
270
+ end
271
+ end
272
+ end
273
+
274
+ namespace :gem do
275
+
276
+ desc 'Install gem'
277
+ task :install => [:build] do
278
+ Gemgem.gem_install
279
+ end
280
+
281
+ desc 'Build gem'
282
+ task :build => [:spec] do
283
+ Gemgem.gem_build
284
+ end
285
+
286
+ desc 'Generate gemspec'
287
+ task :spec do
288
+ Gemgem.gem_spec
289
+ end
290
+
291
+ desc 'Release gem'
292
+ task :release => [:spec, :check, :build] do
293
+ Gemgem.gem_release
294
+ end
295
+
296
+ task :check do
297
+ Gemgem.gem_check
298
+ end
299
+
300
+ end # of gem namespace
301
+
302
+ desc 'Run tests'
303
+ task :test do
304
+ Gemgem.test
305
+ end
306
+
307
+ desc 'Trash ignored files'
308
+ task :clean => ['gem:spec'] do
309
+ Gemgem.clean
310
+ end
311
+
312
+ task :default do
313
+ # Is there a reliable way to do this in the current process?
314
+ # It failed miserably before between Rake versions...
315
+ exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
316
+ end
@@ -0,0 +1,61 @@
1
+
2
+ require 'pork-rspec/test'
3
+
4
+ describe M do
5
+ it { is_expected.to eq(M) }
6
+ it { expect(subject).to eq(M) }
7
+ end
8
+
9
+ describe C do
10
+ it { is_expected.to be_a(C) }
11
+ it { expect(subject).to be_a(C) }
12
+ end
13
+
14
+ describe 'string' do
15
+ it { is_expected.to eq('string') }
16
+ it { expect(subject).to eq('string') }
17
+ end
18
+
19
+ describe M do
20
+ describe 'string' do
21
+ it { is_expected.to eq(M) }
22
+ it { expect(subject).to eq(M) }
23
+ end
24
+ end
25
+
26
+ describe 'parent' do
27
+ describe 'string' do
28
+ it { is_expected.to eq('string') }
29
+ it { expect(subject).to eq('string') }
30
+ end
31
+ end
32
+
33
+ describe 'raise_error' do
34
+ it do
35
+ expect do
36
+ raise 'test'
37
+ end.to raise_error(RuntimeError)
38
+ end
39
+
40
+ it do
41
+ expect do
42
+ raise 'test'
43
+ end.to raise_error(RuntimeError, 'test')
44
+ end
45
+ end
46
+
47
+ describe 'contain_exactly and match_array' do
48
+ it do
49
+ expect([1]).to contain_exactly(1)
50
+ end
51
+
52
+ it do
53
+ expect([1]).to match_array([1])
54
+ end
55
+ end
56
+
57
+ describe 'match' do
58
+ it do
59
+ expect('nnf').to match(/\A\w{3}\z/)
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+
2
+ require 'pork-rspec/test'
3
+
4
+ RSpec.shared_examples "collections" do |collection_class|
5
+ it "is empty when first created" do
6
+ expect(collection_class.new).to be_empty
7
+ end
8
+ end
9
+
10
+ RSpec.describe Array do
11
+ include_examples "collections", Array
12
+ end
13
+
14
+ RSpec.describe Hash do
15
+ include_examples "collections", Hash
16
+ end
17
+
18
+ RSpec.describe C do
19
+ example do
20
+ expect(described_class).to equal(C)
21
+ end
22
+ end
23
+
24
+ RSpec.describe "Using an array as a stack" do
25
+ def build_stack
26
+ []
27
+ end
28
+
29
+ before(:example) do
30
+ @stack = build_stack
31
+ end
32
+
33
+ it 'is initially empty' do
34
+ expect(@stack).to be_empty
35
+ end
36
+
37
+ context "after an item has been pushed" do
38
+ before(:example) do
39
+ @stack.push :item
40
+ end
41
+
42
+ it 'allows the pushed item to be popped' do
43
+ expect(@stack.pop).to eq(:item)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,50 @@
1
+
2
+ require 'pork-rspec/test'
3
+
4
+ describe M, models: true do
5
+ let(:a) { 'a' }
6
+
7
+ it { is_expected.to be_truthy }
8
+ it { expect(subject).to be_truthy }
9
+ it { expect(a).to eq('a') }
10
+
11
+ describe '#m' do
12
+ before do
13
+ @b = [subject.f]
14
+ end
15
+
16
+ it('message') { expect(@b).not_to be_empty }
17
+ it { expect(@b).to contain_exactly('f') }
18
+ end
19
+ end
20
+
21
+ describe 'sum' do
22
+ let(:result) { sum(data) }
23
+
24
+ shared_examples 'sum numbers' do
25
+ it do
26
+ expect(result).to eq(duration)
27
+ end
28
+ end
29
+
30
+ context 'test sample A' do
31
+ let(:data) do
32
+ 0..9
33
+ end
34
+
35
+ let(:duration) { 45 }
36
+
37
+ it_behaves_like 'sum numbers'
38
+ end
39
+
40
+ def sum(data)
41
+ data.inject(0, &:+)
42
+ end
43
+ end
44
+
45
+ describe 'let!' do
46
+ let(:data) { [] }
47
+ let!(:a) { data << 0 }
48
+ before { data << 1 }
49
+ it { expect(a).to contain_exactly(0, 1) }
50
+ end
@@ -0,0 +1,64 @@
1
+
2
+ require 'pork-rspec/test'
3
+
4
+ describe 'mocks' do
5
+ %w[allow expect].each do |kind|
6
+ describe kind do
7
+ title = "The RSpec Book"
8
+
9
+ let(:book) { double("book") }
10
+
11
+ after do
12
+ expect(book.title).to eq(title)
13
+ expect(book.reverse).to eq(title.reverse)
14
+
15
+ if kind == 'expect'
16
+ if Object.const_defined?(:Muack)
17
+ expect{ book.title }.to raise_error(Muack::Expected)
18
+ end
19
+ else
20
+ expect(book.title).to eq(title)
21
+ end
22
+ end
23
+
24
+ it 'receives with a block' do
25
+ send(kind, book).to receive(:title) { title }
26
+ send(kind, book).to receive(:reverse) { title.reverse }
27
+ end
28
+
29
+ it 'receives with and_return' do
30
+ send(kind, book).to receive(:title).and_return(title)
31
+ send(kind, book).to receive(:reverse).and_return(title.reverse)
32
+ end
33
+
34
+ it 'receive_messages' do
35
+ send(kind, book).to receive_messages(:title => title,
36
+ :reverse => title.reverse)
37
+ end
38
+
39
+ context 'just use double' do
40
+ let(:book) { double("book", :title => title,
41
+ :reverse => title.reverse) }
42
+
43
+ it{}
44
+ end if kind == 'allow'
45
+
46
+ context 'unnamed defs' do
47
+ let(:book) { double(:title => title, :reverse => title.reverse) }
48
+
49
+ it{}
50
+ end if kind == 'allow'
51
+ end
52
+ end
53
+
54
+ describe 'and_return with multiple values' do
55
+ let(:die) { double('die') }
56
+
57
+ it do
58
+ allow(die).to receive(:roll).and_return(1, 2, 3)
59
+ [1, 2, 3, 3, 3].each do |result|
60
+ expect(die.roll).to eq(result)
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pork-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Lin Jen-Shin (godfat)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pork
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: muack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: RSpec compatibility layer for Pork.
42
+ email:
43
+ - godfat (XD) godfat.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".gitmodules"
50
+ - ".travis.yml"
51
+ - CHANGES.md
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - lib/pork-rspec.rb
56
+ - lib/pork-rspec/alias.rb
57
+ - lib/pork-rspec/config.rb
58
+ - lib/pork-rspec/context.rb
59
+ - lib/pork-rspec/expect.rb
60
+ - lib/pork-rspec/mock.rb
61
+ - lib/pork-rspec/suite.rb
62
+ - lib/pork-rspec/test.rb
63
+ - pork-rspec.gemspec
64
+ - task/README.md
65
+ - task/gemgem.rb
66
+ - test/test_context.rb
67
+ - test/test_from_doc.rb
68
+ - test/test_misc.rb
69
+ - test/test_mock.rb
70
+ homepage: https://github.com/godfat/pork-rspec
71
+ licenses:
72
+ - Apache License 2.0
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.6.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: RSpec compatibility layer for Pork.
94
+ test_files:
95
+ - test/test_context.rb
96
+ - test/test_from_doc.rb
97
+ - test/test_misc.rb
98
+ - test/test_mock.rb