interchangeable 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac7c4148785998ed665d7ca26b07171dbbc83aac
4
- data.tar.gz: d26b48301c864f75206661fe235f00c96a7482f8
3
+ metadata.gz: 44b42c8bd07198ac3576e8d8e5e40f288733acd9
4
+ data.tar.gz: 89c738f62241cd4fcfa887ff935a815a175ff403
5
5
  SHA512:
6
- metadata.gz: 0da66a26a9c9b051cf21fb9566200fe5c54b09d66377977e31b3d5f20671ef78886b430c927884cdf00a571ad5843cffd5725981957d5b2559be8b8eff638ea2
7
- data.tar.gz: ab5c714337289c4f5a03184991dfc264b30878993913670e6b00539734ba51dd8c9bd139f5d3940e307fee53482cffae9843c15edba091bf031a4679a065b034
6
+ metadata.gz: 86febf2bdfb06f6ae03e0c91e4ec5723b4a8129d0b0990cd1efa40c744ce4a0abc6651388c452c53362ef5369761b37671b6d50bc0035b11e375d37dc27ab01c
7
+ data.tar.gz: 23d3de619effd29617e0726038b9187c54ece9f98717e734e13fc8f334595fe6afa0fd5ad7b8f2c38be9c2b57575b005434c6fed729134719b6387ed24243478
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "mocha"
24
+
25
+ spec.add_runtime_dependency "terminal-table"
23
26
  end
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+
3
+ namespace "interchangeable" do
4
+ desc "show the missing methods"
5
+ task "missing_methods" do
6
+ Kernel.puts Interchangeable::Tables.generate(Interchangeable.missing_methods)
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Interchangeable
2
+ module Tables
3
+ def self.generate methods
4
+ Terminal::Table.new(headings: ['Class', 'Method', 'Description']) do |table|
5
+ methods.each do |method|
6
+ table << [method.target, method.method_name, method.description]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Interchangeable
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'terminal-table'
2
+ require "interchangeable/tables"
1
3
  require "interchangeable/version"
2
4
 
3
5
  class Class
@@ -28,6 +30,10 @@ module Interchangeable
28
30
  @settings ||= []
29
31
  end
30
32
 
33
+ def missing_methods
34
+ methods.reject { |m| m.implemented }
35
+ end
36
+
31
37
  def define the_class, method_name, &block
32
38
  entry = Interchangeable.methods.select { |x| x.target == the_class && x.method_name && method_name }.first
33
39
  unless entry
@@ -0,0 +1,29 @@
1
+ require_relative '../minitest_spec'
2
+ require_relative '../../lib/interchangeable/rake'
3
+
4
+ describe "the rake tasks" do
5
+
6
+ describe "missing" do
7
+
8
+ let(:task_name) { "interchangeable:missing_methods" }
9
+
10
+ it "should include a rake task for returning the missing methods" do
11
+ # this will throw if the method is not defined
12
+ Rake::Task[task_name]
13
+ end
14
+
15
+ it "should output the table" do
16
+ methods = Object.new
17
+ Interchangeable.stubs(:missing_methods).returns methods
18
+
19
+ expected_output = Object.new
20
+ Interchangeable::Tables.stubs(:generate).with(methods).returns expected_output
21
+
22
+ Kernel.expects(:puts).with expected_output
23
+
24
+ Rake::Task[task_name].invoke
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../minitest_spec'
2
+
3
+ describe Interchangeable::Tables do
4
+
5
+ describe "generate" do
6
+
7
+ let(:methods) { [] }
8
+
9
+ let(:table) do
10
+ Interchangeable::Tables.generate methods
11
+ end
12
+
13
+ it "should return a table" do
14
+ table.is_a?(Terminal::Table).must_equal true
15
+ end
16
+
17
+ describe "the header row" do
18
+ it "should set column 0 to the class" do
19
+ table.headings[0].value.must_equal "Class"
20
+ end
21
+
22
+ it "should set column 1 to the method" do
23
+ table.headings[1].value.must_equal "Method"
24
+ end
25
+
26
+ it "should set column 2 to the method" do
27
+ table.headings[2].value.must_equal "Description"
28
+ end
29
+ end
30
+
31
+ describe "with methods" do
32
+
33
+ let(:method_definition) { Struct.new(:target, :method_name, :description) }
34
+
35
+ let(:methods) do
36
+ [
37
+ method_definition.new(Object.new, Object.new, Object.new),
38
+ method_definition.new(Object.new, Object.new, Object.new),
39
+ ]
40
+ end
41
+
42
+ it "should return two rows" do
43
+ table.rows.count.must_equal 2
44
+ end
45
+
46
+ it "should map the target to the first column" do
47
+ table.rows[0][0].value.must_be_same_as methods[0].target
48
+ table.rows[1][0].value.must_be_same_as methods[1].target
49
+ end
50
+
51
+ it "should map the method name to the second column" do
52
+ table.rows[0][1].value.must_be_same_as methods[0].method_name
53
+ table.rows[1][1].value.must_be_same_as methods[1].method_name
54
+ end
55
+
56
+ it "should map the description to the third column" do
57
+ table.rows[0][2].value.must_be_same_as methods[0].description
58
+ table.rows[1][2].value.must_be_same_as methods[1].description
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -226,4 +226,26 @@ describe Interchangeable do
226
226
  end
227
227
  end
228
228
 
229
+ describe "missing methods" do
230
+
231
+ let(:methods) do
232
+ [
233
+ Struct.new(:implemented).new(true),
234
+ Struct.new(:implemented).new(false),
235
+ Struct.new(:implemented).new(true),
236
+ Struct.new(:implemented).new(false),
237
+ ].sort_by { |x| SecureRandom.uuid }
238
+ end
239
+
240
+ it "should return the methods that are not implemented" do
241
+ Interchangeable.stubs(:methods).returns methods
242
+
243
+ results = Interchangeable.missing_methods
244
+ results.count.must_equal 2
245
+
246
+ results.each { |r| r.implemented.must_equal false }
247
+ end
248
+
249
+ end
250
+
229
251
  end
@@ -1,3 +1,4 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/spec'
3
3
  require_relative '../lib/interchangeable'
4
+ require 'mocha/setup'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interchangeable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
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
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description: Extract interchangeable components in your application. Identify them,
42
70
  describe them, and allow others to swap them out easily.
43
71
  email:
@@ -54,7 +82,11 @@ files:
54
82
  - Rakefile
55
83
  - interchangeable.gemspec
56
84
  - lib/interchangeable.rb
85
+ - lib/interchangeable/rake.rb
86
+ - lib/interchangeable/tables.rb
57
87
  - lib/interchangeable/version.rb
88
+ - spec/interchangeable/rake_spec.rb
89
+ - spec/interchangeable/tables_spec.rb
58
90
  - spec/interchangeable_spec.rb
59
91
  - spec/minitest_spec.rb
60
92
  homepage: ''
@@ -82,5 +114,7 @@ signing_key:
82
114
  specification_version: 4
83
115
  summary: Create and describe interchangeable components.
84
116
  test_files:
117
+ - spec/interchangeable/rake_spec.rb
118
+ - spec/interchangeable/tables_spec.rb
85
119
  - spec/interchangeable_spec.rb
86
120
  - spec/minitest_spec.rb