tspec 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a07e9bb4da483559eef421219cb624def8ede4cd
4
- data.tar.gz: 1fe473785a30b27f1160b9108f264817ea259167
3
+ metadata.gz: a54636f321a831faea2655843bad6ce92b99fe65
4
+ data.tar.gz: aab6a5ebe27dd54bbbfd6a2002cc5fcb01034189
5
5
  SHA512:
6
- metadata.gz: 838d9f1c2b18277fcb2a54c41bdb8b9894f8d312775a5a9900307a6e35ab8dee293e805dc7204bb79737c43e58942e8f49347c8f958744a025efd26c2a95b0fb
7
- data.tar.gz: cea0a7a54424d0b0401b8bce18b24d071516db57b15185132b4d0ffd5c5bb7ee2dbdc26f3b0766b220603bea9729e7c723b9a724555cf1c5dc064cce40a8e084
6
+ metadata.gz: 1b5b2c4157f1656b8634add26ed21e442d65e871afd0d91e3daaf89ad31b0fd2d93c70879628c077713970b6fc987b1c369ac5fd9257cdf0f56fdc503bbf448b
7
+ data.tar.gz: fc291a4ed9f314232b7082c036b6917641cfa3ef802f13623ddb0c77e629f9b8d49061368cbef9d5e5761cd496af9e01a140d6acb6278f5be8b4feb75be43aac
data/README.md CHANGED
@@ -37,6 +37,9 @@ require 'tspec'
37
37
  def echo(str)
38
38
  puts str
39
39
  end.receive(str: String)
40
+
41
+ echo('hello world') #=> ok
42
+ echo(123) #=> TSpec::ArgumentTypeError
40
43
  ```
41
44
 
42
45
  You can specify multiple type, too.
@@ -48,8 +51,9 @@ def echo(val)
48
51
  puts val
49
52
  end.receive(val: [String, Float])
50
53
 
51
- echo('hello')
52
- echo(3.14)
54
+ echo('hello') #=> ok
55
+ echo(3.14) #=> ok
56
+ echo(123) #=> TSpec::ArgumentTypeError
53
57
  ```
54
58
 
55
59
  If single method argument is given, you can skip keyword.
@@ -61,7 +65,8 @@ def join_array(arr)
61
65
  arr.join(' ')
62
66
  end.receive([String])
63
67
 
64
- puts join_array(%w(hello world))
68
+ puts join_array(%w(hello world)) #=> ok
69
+ puts join_array([1,2,3]) #=> TSpec::ArgumentTypeError
65
70
  ```
66
71
 
67
72
  You can specify Array content type, although it may seem strange.
@@ -73,7 +78,8 @@ def receive_string_array(arr)
73
78
  arr.join
74
79
  end.receive(arr: [[String]])
75
80
 
76
- puts receive_string_array(['hello', 'world'])
81
+ puts receive_string_array(['hello', 'world']) #=> ok
82
+ puts receive_string_array([:hello, :world]) #=> TSpec::ArgumentTypeError
77
83
  ```
78
84
 
79
85
 
@@ -87,6 +93,13 @@ require 'tspec'
87
93
  def message
88
94
  'hello world'
89
95
  end.return(String)
96
+
97
+ def dummy_message
98
+ 'hello world'
99
+ end.return(Symbol)
100
+
101
+ puts message #=> ok
102
+ puts dummy_message #=> TSpec::ReturnValueTypeError
90
103
  ```
91
104
 
92
105
  You can specify multiple return value, too.
@@ -126,8 +139,8 @@ def string2symbol(str)
126
139
  str.to_sym
127
140
  end.receive(str: String).return(Symbol)
128
141
 
129
- p string2symbol('hello') #=> :hello
130
- p string2symbol(123) #=> TSpec::ArgumentTypeError
142
+ p string2symbol('hello') #=> :hello
143
+ p string2symbol(123) #=> TSpec::ArgumentTypeError
131
144
  ```
132
145
 
133
146
  ## Contributing
@@ -138,4 +151,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/siman-
138
151
  ## License
139
152
 
140
153
  The gem is available under the terms of the [MIT License](http://opensource.org/licenses/MIT).
141
-
@@ -0,0 +1,10 @@
1
+ module TSpec
2
+ class ReturnValueTypeError < StandardError
3
+ end
4
+
5
+ class NotFoundArgumentNameError < StandardError
6
+ end
7
+
8
+ class ArgumentTypeError < StandardError
9
+ end
10
+ end
data/lib/tspec.rb CHANGED
@@ -1,13 +1,4 @@
1
- module TSpec
2
- class ReturnValueTypeError < StandardError
3
- end
4
-
5
- class NotFoundArgumentNameError < StandardError
6
- end
7
-
8
- class ArgumentTypeError < StandardError
9
- end
10
- end
1
+ require 'tspec/type_error'
11
2
 
12
3
  class Symbol
13
4
  def return(*types)
@@ -103,7 +94,11 @@ module TSpec
103
94
 
104
95
  unless value_type_check(value, *type)
105
96
  @type_error_flag = true
106
- raise ArgumentTypeError, "##{tp.method_id} '#{name}' variable should be #{type.inspect}, but actual '#{value.inspect}' - #{value.class}"
97
+ if type.instance_of?(Array)
98
+ raise ArgumentTypeError, "##{tp.method_id} '#{name}' variable should be #{type.map(&:inspect).join(' or ')}, but actual '#{value.inspect}' - #{value.class}"
99
+ else
100
+ raise ArgumentTypeError, "##{tp.method_id} '#{name}' variable should be #{type.inspect}, but actual '#{value.inspect}' - #{value.class}"
101
+ end
107
102
  end
108
103
  end
109
104
  end
data/tspec.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "tspec"
7
- spec.version = "0.2.0"
7
+ spec.version = "0.3.0"
8
8
  spec.authors = ["siman-man"]
9
9
  spec.email = ["k128585@ie.u-ryukyu.ac.jp"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - siman-man
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - examples/return_failed.rb
75
75
  - examples/return_success.rb
76
76
  - lib/tspec.rb
77
+ - lib/tspec/type_error.rb
77
78
  - tspec.gemspec
78
79
  homepage: https://github.com/siman-man/tspec
79
80
  licenses: