pry-power_assert 0.0.1

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: e97d070244dac7b4d9ea88f9aafbc4164859be5f
4
+ data.tar.gz: ac5adbd0469ea4e78c4197a7dc272ba2b3e9a21b
5
+ SHA512:
6
+ metadata.gz: aa3976d9bb3d7cdff439f402bacf60b42ba474d6d8d46e05964bdf2399651adbf2fa3c4555254c57c962b7401695784a0b3fc77d3489b92530ee2c8fc57943f9
7
+ data.tar.gz: 3896e15bc221b6f6c51a0815795fb9acfa067ff50a6513f1c556e539bc3e61a263e06531ccae86079fdfc4f0b172782b6d75602a8a2072aed55d37282e4400ab
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ vendor/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-power_assert.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 yui-knk
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,49 @@
1
+ # PryPowerAssert
2
+
3
+ Provides power assert support for Pry
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pry-power_assert'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pry-power_assert
20
+
21
+ ## Usage
22
+
23
+ Start Pry.
24
+
25
+ ```shell
26
+ $ pry
27
+ ```
28
+
29
+ Type `pa RUBY_CODE`
30
+
31
+ ```ruby
32
+ [1] pry(main)> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class
33
+ "0".class == "3".to_i.times.map {|i| i + 1 }.class
34
+ | | | | | |
35
+ | | | | | Array
36
+ | | | | [1, 2, 3]
37
+ | | | #<Enumerator: 3:times>
38
+ | | 3
39
+ | false
40
+ String
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/yui-knk/pry-power_assert/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,45 @@
1
+ require "power_assert"
2
+
3
+ module PowerAssert
4
+ class PryContext < Context
5
+
6
+ # args line means assertion_proc_string
7
+ def initialize(assertion_proc, assertion_method, line)
8
+ @line = line
9
+ methods = nil
10
+ refs = nil
11
+ method_ids = nil
12
+ return_values = []
13
+ @base_caller_length = -1
14
+ @assertion_proc = assertion_proc
15
+ @assertion_method_name = assertion_method.to_s
16
+ @message_proc = -> {
17
+ @assertion_message ||=
18
+ @base_caller_length > 0 ? assertion_message(@line || '',
19
+ methods || [],
20
+ return_values,
21
+ refs || [],
22
+ assertion_proc.binding).freeze :
23
+ nil
24
+ }
25
+ @proc_local_variables = assertion_proc.binding.eval('local_variables').map(&:to_s)
26
+ @trace = TracePoint.new(:return, :c_return) do |tp|
27
+ next if method_ids and ! method_ids.include?(tp.method_id)
28
+ locs = tp.binding.eval('caller_locations')
29
+ if locs.length - @base_caller_length == TARGET_CALLER_DIFF[tp.event]
30
+ idx = TARGET_CALLER_INDEX[tp.event]
31
+ idents = extract_idents(Ripper.sexp(@line))
32
+ methods, refs = idents.partition {|i| i.type == :method }
33
+ method_ids = methods.map(&:name).map(&:to_sym).uniq
34
+ return_values << Value[tp.method_id.to_s, tp.return_value, nil]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ private_constant :PryContext
40
+
41
+ def start_with_string(assertion_proc, line, assertion_method: nil)
42
+ yield PryContext.new(assertion_proc, assertion_method, line)
43
+ end
44
+ module_function :start_with_string
45
+ end
@@ -0,0 +1,3 @@
1
+ module PryPowerAssert
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,39 @@
1
+ require "pry"
2
+ require "pry-power_assert/version"
3
+ require "pry-power_assert/power_assert-ext"
4
+
5
+ module PryPowerAssert
6
+ Pry::Commands.create_command('pa', '') do
7
+
8
+ banner <<-'BANNER'
9
+ Usage: pa RUBY_CODE
10
+
11
+ The pa command show RUBY_CODE result with power_assert like format.
12
+
13
+ [1] pry(main)> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class
14
+ "0".class == "3".to_i.times.map {|i| i + 1 }.class
15
+ | | | | | |
16
+ | | | | | Array
17
+ | | | | [1, 2, 3]
18
+ | | | #<Enumerator: 3:times>
19
+ | | 3
20
+ | false
21
+ String
22
+ BANNER
23
+
24
+ def process
25
+ result = ""
26
+ code = arg_string
27
+
28
+ proc = context[:target].eval "Proc.new {#{code}}"
29
+
30
+ PowerAssert.start_with_string(proc, code, assertion_method: __method__) do |pa|
31
+ pa.yield
32
+ result = pa.message_proc.()
33
+ end
34
+
35
+ output.puts result
36
+ end
37
+
38
+ end
39
+ 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-power_assert/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pry-power_assert"
8
+ spec.version = PryPowerAssert::VERSION
9
+ spec.authors = ["yui-knk"]
10
+ spec.email = ["spiketeika@gmail.com"]
11
+ spec.summary = "Provides power assert support for Pry"
12
+ spec.description = "Provides power assert support for Pry"
13
+ spec.homepage = "https://github.com/yui-knk/pry-power_assert"
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_dependency "power_assert", "0.1.3"
22
+ spec.add_dependency "pry", ">= 0.9.8"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,43 @@
1
+ require 'pry/test/helper'
2
+ require 'pry-power_assert'
3
+
4
+ describe "ps command" do
5
+ it "should show power_assert result" do
6
+ pry_eval(%q{pa "0".class == "3".to_i.times.map {|i| i + 1 }.class}).chomp.should == <<END.chomp
7
+ "0".class == "3".to_i.times.map {|i| i + 1 }.class
8
+ | | | | | |
9
+ | | | | | Array
10
+ | | | | [1, 2, 3]
11
+ | | | #<Enumerator: 3:times>
12
+ | | 3
13
+ | false
14
+ String
15
+ END
16
+ end
17
+
18
+ it "should show power_assert result" do
19
+ pry_eval(%q{a = 10})
20
+ pry_eval(%q{b = 20})
21
+ pry_eval(%q{pa a + b + 30}).chomp.should == <<END.chomp
22
+ a + b + 30
23
+ | | | |
24
+ | | | 60
25
+ | | 20
26
+ | 30
27
+ 10
28
+ END
29
+ end
30
+
31
+ it "should show power_assert result" do
32
+ pry_eval(%q{@a = 10})
33
+ pry_eval(%q{@b = 20})
34
+ pry_eval(%q{pa @a + @b + 30}).chomp.should == <<END.chomp
35
+ @a + @b + 30
36
+ | | | |
37
+ | | | 60
38
+ | | 20
39
+ | 30
40
+ 10
41
+ END
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-power_assert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yui-knk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: power_assert
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Provides power assert support for Pry
70
+ email:
71
+ - spiketeika@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/pry-power_assert.rb
82
+ - lib/pry-power_assert/power_assert-ext.rb
83
+ - lib/pry-power_assert/version.rb
84
+ - pry-power_assert.gemspec
85
+ - spec/pry-power_assert_spec.rb
86
+ homepage: https://github.com/yui-knk/pry-power_assert
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Provides power assert support for Pry
110
+ test_files:
111
+ - spec/pry-power_assert_spec.rb
112
+ has_rdoc: