mkspec 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.ruby-version +1 -1
- data/.travis.yml +16 -0
- data/Gemfile +3 -0
- data/README.md +41 -3
- data/Rakefile +4 -0
- data/lib/mkspec/version.rb +1 -1
- data/lib/mkspec.rb +19 -6
- data/spec/mkspec_spec.rb +35 -1
- data/spec/spec_helper.rb +5 -0
- metadata +9 -14
- data/Gemfile.lock +0 -18
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmQxOThiYzUxZGJjOTc5Yzg2N2NlNTlkZjI0MmExMWU0NWUxOWZlOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTdhZTFmY2QzYmY2NTAyN2ZkMDI0Mjk5ODU4OTRmYzkwOGIwYWIyNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjY0ZmJhZTQ2NjA2ZTNkYTRlYmNhM2I3ZWE2MjBlNDcxZmExNzcxYjA5MDMw
|
10
|
+
YTU4YzA0YjRhNzc4OTE3YzZlNzU0YWNjMWE0Y2MyYmFhYzJmNTA4MDRmMjJi
|
11
|
+
MjM2NTA2ZjRhZTAwMTU1OTk1YzhlMTI1Y2M2ZjZmNDQwNmMwZjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTJhODY5YzdkZDFiM2RjMjQ2OWFhNWYyYWJiNjRhYTgwOTBmZjM1YTA5OWNj
|
14
|
+
MDIzZmY1ZjIzMDI3NDUyZTc1ZTJlMGRkOWUzNmJjNGIyMjNmMTg1OGEzZThl
|
15
|
+
Njg5Nzc2ZGIxMmQyYmZiZDZlMTliMDY3ZjAxYzBjYzNkZWZhNDU=
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0-p247
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args:
|
3
|
+
rvm:
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
addons:
|
7
|
+
code_climate:
|
8
|
+
repo_token: 66f413f9c50c6bc2d265e217df307f5de8bf36d8ad97feffb76b0174e9f9acd5
|
9
|
+
deploy:
|
10
|
+
provider: rubygems
|
11
|
+
api_key:
|
12
|
+
secure: WLQzsGZ6aPzqsyS1Mu4YCZjer4ZXRFQo5j1XPkTdR/bYmip2GBQAoVIUihlIXrcTSDKRk4VVZ62GkVSOkTA41vAVvD69ARGNIgwSDzLfoVp7RWEIi7peUBdYhzOoQM8eFnOKa3UeZbEqjolsTjtQfMQISNCeL9TCmdRcyLa/avk=
|
13
|
+
gem: mkspec
|
14
|
+
on:
|
15
|
+
tags: true
|
16
|
+
repo: ritchiey/mkspec
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Mkspec
|
2
2
|
======
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mkspec.png)](http://badge.fury.io/rb/mkspec)
|
4
|
+
[![Build Status](https://travis-ci.org/ritchiey/mkspec.png?branch=master)](https://travis-ci.org/ritchiey/mkspec)
|
5
|
+
[![Code Climate](https://codeclimate.com/repos/52b530917e00a45ef600294e/badges/9bce4690fe2eca6f2062/gpa.png)](https://codeclimate.com/repos/52b530917e00a45ef600294e/feed)
|
3
6
|
|
4
7
|
Generate your Ruby specs straight from your REPL
|
5
8
|
|
@@ -7,10 +10,9 @@ Whilst mucking around in your Ruby REPL (probably Pry), you decide you
|
|
7
10
|
need a spec to describe your next great feature. Instead of jumping back
|
8
11
|
to your editor, just type:
|
9
12
|
|
10
|
-
|
11
|
-
include Mkspec
|
13
|
+
extend Mkspec
|
12
14
|
|
13
|
-
expect(calculator, :calculate, "1+1").to(eq(1+1))
|
15
|
+
puts expect(calculator, :calculate, "1+1").to(eq(1+1))
|
14
16
|
|
15
17
|
and it will generate:
|
16
18
|
|
@@ -25,6 +27,42 @@ and it will generate:
|
|
25
27
|
|
26
28
|
end
|
27
29
|
end
|
30
|
+
|
31
|
+
You can then copy and paste that spec into a file and edit to taste. It's not perfect but it does give you a headstart with some of the boiler-plate.
|
32
|
+
|
33
|
+
Motivation
|
34
|
+
==========
|
35
|
+
|
36
|
+
The advantage of generating the spec from within Pry is that you are working with real values from the calling method. This enables you to just put `binding.pry` at the top of a method you need to implement and generate a realistic spec for it based on the values it actually received when called.
|
37
|
+
|
38
|
+
|
39
|
+
Installation
|
40
|
+
============
|
41
|
+
|
42
|
+
Add this to your Gemfile:
|
43
|
+
|
44
|
+
gem 'mkspec'
|
45
|
+
|
46
|
+
and run `bundle` at the command prompt to install it.
|
47
|
+
|
48
|
+
|
49
|
+
Usage
|
50
|
+
=====
|
51
|
+
|
52
|
+
Where possible, mkspec syntax follows that of RSpec so it will hopefully be familiar.
|
53
|
+
|
54
|
+
expect(object_to_test, method, params...).to eq(expected_value)
|
55
|
+
|
56
|
+
|
57
|
+
It uses Ruby's PrettyPrint to serialise `params` and `expected_value` so it correctly serializes Hashes and Arrays.
|
58
|
+
|
59
|
+
See the specs for more examples of usage.
|
60
|
+
|
61
|
+
|
62
|
+
Bugs
|
63
|
+
====
|
64
|
+
|
65
|
+
Mkspec does what it can to create a useful spec from the values it can introspect. It doesn't always get it right though so you'll very likely need to edit the generated spec a little.
|
28
66
|
|
29
67
|
WIP
|
30
68
|
===
|
data/Rakefile
CHANGED
data/lib/mkspec/version.rb
CHANGED
data/lib/mkspec.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
module Mkspec
|
2
2
|
|
3
|
-
class Matcher
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
3
|
class LeftHand
|
8
4
|
|
9
5
|
def initialize(class_name, method_name, args)
|
@@ -20,16 +16,33 @@ describe #{@class_name} do
|
|
20
16
|
describe "##{@method_name}" do
|
21
17
|
|
22
18
|
it "does something" do
|
23
|
-
expect(subject.#{@method_name}(
|
19
|
+
expect(subject.#{@method_name}(#{@args.map{|arg| serialise(arg) }.join(', ')})).to #{matcher}
|
24
20
|
end
|
25
21
|
|
26
22
|
end
|
27
23
|
end
|
28
24
|
EOF
|
29
25
|
end
|
26
|
+
|
27
|
+
# Attempt to recreate the source-code to represent this argument in the setup
|
28
|
+
# for our generated spec.
|
29
|
+
def serialise(arg)
|
30
|
+
if %w(Array Hash Float Fixnum String).include? arg.class.name
|
31
|
+
arg.pretty_inspect.chop
|
32
|
+
else
|
33
|
+
guess_constructor arg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Don't recognise the type so we don't know how to recreate it
|
38
|
+
# in source code. So we'll take a guess at what might work and
|
39
|
+
# let the user fix it up if necessary.
|
40
|
+
def guess_constructor(arg)
|
41
|
+
"#{arg.class.name}.new(#{serialise(arg.to_s)})"
|
42
|
+
end
|
30
43
|
end
|
31
44
|
|
32
|
-
def expect(sut, method, args)
|
45
|
+
def expect(sut, method, *args)
|
33
46
|
LeftHand.new(sut.class.name, method, args)
|
34
47
|
end
|
35
48
|
|
data/spec/mkspec_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
2
3
|
|
3
4
|
describe Mkspec do
|
4
5
|
|
@@ -25,4 +26,37 @@ end
|
|
25
26
|
)
|
26
27
|
end
|
27
28
|
|
29
|
+
|
30
|
+
it "can generate specs for methods with varying arity and parameter types" do
|
31
|
+
class CustomType
|
32
|
+
def initialize(str)
|
33
|
+
@value = str.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
@value.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
class SystemUnderTest
|
41
|
+
end
|
42
|
+
sut = SystemUnderTest.new
|
43
|
+
|
44
|
+
sut.extend described_class
|
45
|
+
expect(sut.expect(sut, :calculate, CustomType.new('1'), '+', 5.4, {formats:[:pdf, 'html']}).to(sut.eq(1+5.4)).to_s).to eq(
|
46
|
+
<<-GENERATED_SPEC
|
47
|
+
describe SystemUnderTest do
|
48
|
+
subject {described_class.new}
|
49
|
+
|
50
|
+
describe "#calculate" do
|
51
|
+
|
52
|
+
it "does something" do
|
53
|
+
expect(subject.calculate(CustomType.new("1"), "+", 5.4, {:formats=>[:pdf, "html"]})).to eq(6.4)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
GENERATED_SPEC
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
28
62
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mkspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ritchie Young
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -68,8 +61,8 @@ extra_rdoc_files: []
|
|
68
61
|
files:
|
69
62
|
- .gitignore
|
70
63
|
- .ruby-version
|
64
|
+
- .travis.yml
|
71
65
|
- Gemfile
|
72
|
-
- Gemfile.lock
|
73
66
|
- LICENSE
|
74
67
|
- LICENSE.txt
|
75
68
|
- README.md
|
@@ -78,30 +71,32 @@ files:
|
|
78
71
|
- lib/mkspec/version.rb
|
79
72
|
- mkspec.gemspec
|
80
73
|
- spec/mkspec_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
81
75
|
homepage: https://github.com/ritchiey/mkspec
|
82
76
|
licenses:
|
83
77
|
- MIT
|
78
|
+
metadata: {}
|
84
79
|
post_install_message:
|
85
80
|
rdoc_options: []
|
86
81
|
require_paths:
|
87
82
|
- lib
|
88
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
84
|
requirements:
|
91
85
|
- - ! '>='
|
92
86
|
- !ruby/object:Gem::Version
|
93
87
|
version: '0'
|
94
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
89
|
requirements:
|
97
90
|
- - ! '>='
|
98
91
|
- !ruby/object:Gem::Version
|
99
92
|
version: '0'
|
100
93
|
requirements: []
|
101
94
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 2.1.11
|
103
96
|
signing_key:
|
104
|
-
specification_version:
|
97
|
+
specification_version: 4
|
105
98
|
summary: Generate a spec from your REPL using a simple, familiar DSL
|
106
99
|
test_files:
|
107
100
|
- spec/mkspec_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
diff-lcs (1.2.4)
|
5
|
-
rspec (2.14.1)
|
6
|
-
rspec-core (~> 2.14.0)
|
7
|
-
rspec-expectations (~> 2.14.0)
|
8
|
-
rspec-mocks (~> 2.14.0)
|
9
|
-
rspec-core (2.14.5)
|
10
|
-
rspec-expectations (2.14.2)
|
11
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
12
|
-
rspec-mocks (2.14.3)
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
rspec
|