pry_test_case 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +11 -0
- data/Gemfile +16 -0
- data/Guardfile +6 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +9 -0
- data/lib/pry_test_case.rb +6 -0
- data/lib/pry_test_case/command_helpers.rb +72 -0
- data/lib/pry_test_case/version.rb +4 -0
- data/pry_test_case.gemspec +26 -0
- data/test/test_helper.rb +6 -0
- data/test/test_helpers/coverage.rb +7 -0
- data/test/test_helpers/test_case.rb +11 -0
- data/test/unit/command_helpers_test.rb +81 -0
- data/test/unit/pry_test_case_test.rb +24 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1a76df0eb0f7de7bb2523abcd4750411680700e
|
4
|
+
data.tar.gz: 1e1dc6128bfe0607a66b927952af3d68e41edd73
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a610a5aa1750c2423ee0e3687666e78452d506762e733d4b9539a14e7b63c03e4c64d1befb67731db2bdc2ce8504c8e4b4e81ed00acd9d8c112aba3219060e0
|
7
|
+
data.tar.gz: d94dff19e1f5442630e48f9ae1139cfd614e70282ffc1224d5cbbb93e2b808744865ae4da724b306db4f6776b48f6f14405a30ce2faeb50d9de6cfdce9ec64d2
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :doc do
|
6
|
+
gem "yard"
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "coveralls", :require => false
|
11
|
+
gem "guard"
|
12
|
+
gem "guard-minitest"
|
13
|
+
gem "minitest", ">= 3.0"
|
14
|
+
gem "mocha"
|
15
|
+
gem "simplecov", :require => false
|
16
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
guard(:minitest, :all_after_pass => false, :all_on_start => false) do
|
2
|
+
watch(%r{^lib/pry_test_case/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
3
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
4
|
+
watch(%r{^test/.+_test\.rb$})
|
5
|
+
watch(%r{^(lib/pry_test_case|test/test_helper)\.rb$}) { "test" }
|
6
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Danny Guinther
|
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,46 @@
|
|
1
|
+
# PryTestCase
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/pry_test_case.svg)](http://badge.fury.io/rb/pry_test_case)
|
3
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/pry_test_case)
|
4
|
+
[![Build Status](https://travis-ci.org/tdg5/pry_test_case.svg)](https://travis-ci.org/tdg5/pry_test_case)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/tdg5/pry_test_case/badge.svg)](https://coveralls.io/r/tdg5/pry_test_case)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/tdg5/pry_test_case/badges/gpa.svg)](https://codeclimate.com/github/tdg5/pry_test_case)
|
7
|
+
[![Dependency Status](https://gemnasium.com/tdg5/pry_test_case.svg)](https://gemnasium.com/tdg5/pry_test_case)
|
8
|
+
|
9
|
+
Library providing a test case class and other helpers for testing Pry commands
|
10
|
+
and extensions.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'pry_test_case'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ gem install pry_test_case
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Require the library in your `test_helper.rb` or similar file:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require "pry_test_case"
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/tdg5/pry_test_case/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Mixin providing methods for executing Pry commands in various contexts and
|
2
|
+
# environments.
|
3
|
+
module PryTestCase::CommandHelpers
|
4
|
+
# Evaluates the given command string as the Pry CLI would evaluate it. Behaves
|
5
|
+
# more like executing the given command in a live Pry session would. This
|
6
|
+
# means that Pry will intercept some behaviors that may be valuable to your
|
7
|
+
# tests. For more direct access to the results and errors of a command
|
8
|
+
# execution, see {#command_exec_direct}.
|
9
|
+
#
|
10
|
+
# @param [String] command_string The command string to execute including any
|
11
|
+
# arguments that the command string might take.
|
12
|
+
# @param [Hash] options Optional arguments for manipulating the command
|
13
|
+
# execution environment.
|
14
|
+
# @option options [Binding] :target (TOPLEVEL_BINDING) The target Binding that the command should
|
15
|
+
# be executed in. Also aliased as *:context*.
|
16
|
+
# @option options [Boolean] :show_output (true) Flag indicating whether or not the
|
17
|
+
# output of the command should be displayed.
|
18
|
+
# @option options [IO] :output (Pry.config.output) The IO object that the
|
19
|
+
# output of the command should be written to. If *:show_output* is false,
|
20
|
+
# the given IO object will be ignored and a new StringIO object will be used
|
21
|
+
# instead.
|
22
|
+
# @option options [Pry::CommandSet] :commands (Pry.config.commands) The
|
23
|
+
# command set that the generated Pry instance should be created with.
|
24
|
+
# @return [Object] The result of the command execution. The exact value
|
25
|
+
# returned varies depending on the command.
|
26
|
+
# @see #command_exec_direct
|
27
|
+
def command_exec_cli(command_string, options = {})
|
28
|
+
Pry.run_command(command_string, options)
|
29
|
+
result = Pry.current[:pry_cmd_result]
|
30
|
+
result && result.retval != Pry::Command::VOID_VALUE ? result.retval : result
|
31
|
+
end
|
32
|
+
|
33
|
+
# Evaluates the given command string and runs the command directly without
|
34
|
+
# going through the Pry CLI eval cycle. Allows more direct access to errors
|
35
|
+
# and other things the CLI can make hard to get direct access to. To execute a
|
36
|
+
# command in an environment more similar to a live Pry session, see
|
37
|
+
# {#command_exec_cli}.
|
38
|
+
#
|
39
|
+
# @param [String] command_string The command string to execute including any
|
40
|
+
# arguments that the command string might take.
|
41
|
+
# @param [Hash] options Optional arguments for manipulating the command
|
42
|
+
# execution environment.
|
43
|
+
# @option options [Binding] :target (TOPLEVEL_BINDING) The target Binding that the command should
|
44
|
+
# be executed in. Also aliased as *:context*.
|
45
|
+
# @option options [IO] :output (Pry.config.output) The IO object that the
|
46
|
+
# output of the command should be written to.
|
47
|
+
# @option options [Pry::CommandSet] :command_set (Pry.config.commands) The
|
48
|
+
# command set that should be passed to the specified command when it is
|
49
|
+
# initialized.
|
50
|
+
# @option options [Pry] :pry_instance The Pry instance that should be passed
|
51
|
+
# to the specified command when it is initialized. By default a new Pry
|
52
|
+
# instance will be generated from the given options.
|
53
|
+
# @return [Object] The result of the command execution. The exact value
|
54
|
+
# returned varies depending on the command.
|
55
|
+
# @see #command_exec_cli
|
56
|
+
def command_exec_direct(command_string, options = {})
|
57
|
+
exec_options = {
|
58
|
+
:target => TOPLEVEL_BINDING,
|
59
|
+
:output => Pry.config.output,
|
60
|
+
:command_set => Pry.config.commands,
|
61
|
+
}.merge!(options)
|
62
|
+
exec_options[:eval_string] = command_string
|
63
|
+
exec_options[:pry_instance] ||= Pry.new({
|
64
|
+
:target => exec_options[:target],
|
65
|
+
:output => exec_options[:output],
|
66
|
+
:commands => exec_options[:command_set],
|
67
|
+
})
|
68
|
+
args = command_string.split(/\s+/)
|
69
|
+
match = args.shift
|
70
|
+
Pry.commands.run_command(exec_options, match, *args)
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "pry_test_case/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pry_test_case"
|
8
|
+
spec.version = PryTestCase::VERSION
|
9
|
+
spec.authors = ["Danny Guinther"]
|
10
|
+
spec.email = ["dannyguinther@gmail.com"]
|
11
|
+
spec.summary = "Library for testing Pry commands and extensions."
|
12
|
+
spec.description = <<-DESC
|
13
|
+
Library providing a test case class and other helpers for
|
14
|
+
testing Pry commands and extensions.
|
15
|
+
DESC
|
16
|
+
spec.homepage = "https://github.com/tdg5/pry_test_case"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.test_files = spec.files.grep(%r{^test/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 0"
|
25
|
+
spec.add_development_dependency "pry", "~> 0"
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "pry_test_case/command_helpers"
|
3
|
+
|
4
|
+
module PryTestCase::Test
|
5
|
+
class CommandHelpersTest < TestCase
|
6
|
+
Subject = PryTestCase::CommandHelpers
|
7
|
+
TestSubject = Class.new { include Subject }
|
8
|
+
Pry.commands.create_command("command-with-return-value", :keep_retval => true) do
|
9
|
+
def process
|
10
|
+
args.first
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context Subject.name do
|
15
|
+
subject { TestSubject.new }
|
16
|
+
|
17
|
+
context "#command_exec_cli" do
|
18
|
+
should "pass the given command and options directly to Pry.run_command" do
|
19
|
+
command = "some-command"
|
20
|
+
options = { :fake => :options }
|
21
|
+
# Replicate bypassed side-effect
|
22
|
+
(mock_result = mock).stubs(:retval).returns(true)
|
23
|
+
Pry.current[:pry_cmd_result] = mock_result
|
24
|
+
Pry.expects(:run_command).with(command, options)
|
25
|
+
subject.command_exec_cli(command, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "return the result of the command" do
|
29
|
+
expected_value = "result"
|
30
|
+
result = subject.command_exec_cli("command-with-return-value #{expected_value}", :show_output => false)
|
31
|
+
assert_equal expected_value, result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "#command_exec_direct" do
|
36
|
+
setup do
|
37
|
+
@command = "some-command"
|
38
|
+
@arg = "with_args"
|
39
|
+
@command_with_arg = "#{@command} #{@arg}"
|
40
|
+
end
|
41
|
+
|
42
|
+
should "pass the given command and options to Pry.commands.run_command" do
|
43
|
+
opts = {
|
44
|
+
:target => "target",
|
45
|
+
:output => "output",
|
46
|
+
:command_set => "command_set",
|
47
|
+
:pry_instance => "pry_instance",
|
48
|
+
}
|
49
|
+
expected_opts = opts.merge(:eval_string => @command_with_arg)
|
50
|
+
Pry.commands.expects(:run_command).with(expected_opts, @command, @arg)
|
51
|
+
subject.command_exec_direct(@command_with_arg, opts)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "generate sane defaults for options not given" do
|
55
|
+
expected_opts = {
|
56
|
+
:command_set => Pry.config.commands,
|
57
|
+
:eval_string => @command_with_arg,
|
58
|
+
:output => Pry.config.output,
|
59
|
+
:target => TOPLEVEL_BINDING,
|
60
|
+
}
|
61
|
+
pry_instance_opts = {
|
62
|
+
:commands => expected_opts[:command_set],
|
63
|
+
:output => expected_opts[:output],
|
64
|
+
:target => expected_opts[:target],
|
65
|
+
}
|
66
|
+
pry_instance = Pry.new(pry_instance_opts.dup)
|
67
|
+
Pry.expects(:new).with(pry_instance_opts).returns(pry_instance)
|
68
|
+
expected_opts[:pry_instance] = pry_instance
|
69
|
+
Pry.commands.expects(:run_command).with(expected_opts, @command, @arg)
|
70
|
+
subject.command_exec_direct(@command_with_arg)
|
71
|
+
end
|
72
|
+
|
73
|
+
should "return the result of the command" do
|
74
|
+
expected_value = "result"
|
75
|
+
result = subject.command_exec_direct("command-with-return-value #{expected_value}", :output => StringIO.new)
|
76
|
+
assert_equal expected_value, result
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PryTestCase::Test
|
4
|
+
class PryTestCaseTest < TestCase
|
5
|
+
Subject = PryTestCase
|
6
|
+
|
7
|
+
context Subject.name do
|
8
|
+
should "be defined" do
|
9
|
+
msg = "Expected Subject to refer to a module of a different name"
|
10
|
+
refute_equal "Subject", Subject.name, msg
|
11
|
+
|
12
|
+
msg = "Could not find #{Subject.name} module"
|
13
|
+
assert Object.const_defined?(Subject.name), msg
|
14
|
+
end
|
15
|
+
|
16
|
+
should "define a semantic version" do
|
17
|
+
msg = "Could not find version constant!"
|
18
|
+
assert Subject.const_defined?(:VERSION), msg
|
19
|
+
|
20
|
+
assert_match(/\d+\.\d+\.\d+/, Subject.const_get(:VERSION))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry_test_case
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Guinther
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-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: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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: pry
|
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
|
+
description: |2
|
56
|
+
Library providing a test case class and other helpers for
|
57
|
+
testing Pry commands and extensions.
|
58
|
+
email:
|
59
|
+
- dannyguinther@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Guardfile
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/pry_test_case.rb
|
72
|
+
- lib/pry_test_case/command_helpers.rb
|
73
|
+
- lib/pry_test_case/version.rb
|
74
|
+
- pry_test_case.gemspec
|
75
|
+
- test/test_helper.rb
|
76
|
+
- test/test_helpers/coverage.rb
|
77
|
+
- test/test_helpers/test_case.rb
|
78
|
+
- test/unit/command_helpers_test.rb
|
79
|
+
- test/unit/pry_test_case_test.rb
|
80
|
+
homepage: https://github.com/tdg5/pry_test_case
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.2.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Library for testing Pry commands and extensions.
|
104
|
+
test_files:
|
105
|
+
- test/test_helper.rb
|
106
|
+
- test/test_helpers/coverage.rb
|
107
|
+
- test/test_helpers/test_case.rb
|
108
|
+
- test/unit/command_helpers_test.rb
|
109
|
+
- test/unit/pry_test_case_test.rb
|
110
|
+
has_rdoc:
|