rspec-encoding-matchers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +210 -0
- data/Rakefile +2 -0
- data/lib/rspec_encoding_matchers.rb +20 -0
- data/lib/rspec_encoding_matchers/version.rb +3 -0
- data/rspec-encoding-matchers.gemspec +25 -0
- data/spec/encoding_matcher_spec.rb +35 -0
- data/spec/spec_helper.rb +9 -0
- metadata +107 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "autotest/bundler"
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
RSpec Encoding Matchers
|
2
|
+
=======================
|
3
|
+
|
4
|
+
Provides RSpec matchers for Ruby 1.9 string encoding.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
`gem install rspec-encoding-matchers`
|
10
|
+
|
11
|
+
Then require the gem:
|
12
|
+
|
13
|
+
`require 'rspec_encoding_matchers'`
|
14
|
+
|
15
|
+
Configuration
|
16
|
+
-------------
|
17
|
+
|
18
|
+
To use the custom matchers, include the matcher module either in an example group:
|
19
|
+
|
20
|
+
describe "my group" do
|
21
|
+
include RspecEncodingMatchers
|
22
|
+
it "is encoded in UTF-8" do
|
23
|
+
hello.should be_encoded_as("UTF-8")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Or you can include the module in your RSpec configuration.
|
28
|
+
|
29
|
+
# spec_helper.rb
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.color_enabled = true
|
32
|
+
config.include RSpecEncodingMatchers
|
33
|
+
end
|
34
|
+
|
35
|
+
Usage
|
36
|
+
-----
|
37
|
+
|
38
|
+
RSpecEncodingMatchers provides two types of matchers. The first type, `be_encoded_as`, matches to see if the subject is the encoding passed in as a parameter.
|
39
|
+
|
40
|
+
"my string".should be_encoded_as("UTF-8")
|
41
|
+
|
42
|
+
RSpecEncodingMatchers also provides built in matchers for all known string encodings (and their alternate names) to Ruby. For example:
|
43
|
+
|
44
|
+
"my string".should be_iso_8859_1_encoded
|
45
|
+
|
46
|
+
Presently, the following built in encoding matchers are available.
|
47
|
+
|
48
|
+
* be\_ascii\_8bit\_encoded
|
49
|
+
* be\_binary\_encoded
|
50
|
+
* be\_utf\_8\_encoded
|
51
|
+
* be\_cp65001\_encoded
|
52
|
+
* be\_locale\_encoded
|
53
|
+
* be\_external\_encoded
|
54
|
+
* be\_filesystem\_encoded
|
55
|
+
* be\_us\_ascii\_encoded
|
56
|
+
* be\_ascii\_encoded
|
57
|
+
* be\_ansi\_x3.4\_1968\_encoded
|
58
|
+
* be\_646\_encoded
|
59
|
+
* be\_big5\_encoded
|
60
|
+
* be\_cp950\_encoded
|
61
|
+
* be\_big5\_hkscs\_encoded
|
62
|
+
* be\_cp951\_encoded
|
63
|
+
* be\_big5\_uao\_encoded
|
64
|
+
* be\_cp949\_encoded
|
65
|
+
* be\_emacs\_mule\_encoded
|
66
|
+
* be\_euc\_jp\_encoded
|
67
|
+
* be\_eucjp\_encoded
|
68
|
+
* be\_euc\_kr\_encoded
|
69
|
+
* be\_euckr\_encoded
|
70
|
+
* be\_euc\_tw\_encoded
|
71
|
+
* be\_euctw\_encoded
|
72
|
+
* be\_gb18030\_encoded
|
73
|
+
* be\_gbk\_encoded
|
74
|
+
* be\_cp936\_encoded
|
75
|
+
* be\_iso\_8859\_1\_encoded
|
76
|
+
* be\_iso8859\_1\_encoded
|
77
|
+
* be\_iso\_8859\_2\_encoded
|
78
|
+
* be\_iso8859\_2\_encoded
|
79
|
+
* be\_iso\_8859\_3\_encoded
|
80
|
+
* be\_iso8859\_3\_encoded
|
81
|
+
* be\_iso\_8859\_4\_encoded
|
82
|
+
* be\_iso8859\_4\_encoded
|
83
|
+
* be\_iso\_8859\_5\_encoded
|
84
|
+
* be\_iso8859\_5\_encoded
|
85
|
+
* be\_iso\_8859\_6\_encoded
|
86
|
+
* be\_iso8859\_6\_encoded
|
87
|
+
* be\_iso\_8859\_7\_encoded
|
88
|
+
* be\_iso8859\_7\_encoded
|
89
|
+
* be\_iso\_8859\_8\_encoded
|
90
|
+
* be\_iso8859\_8\_encoded
|
91
|
+
* be\_iso\_8859\_9\_encoded
|
92
|
+
* be\_iso8859\_9\_encoded
|
93
|
+
* be\_iso\_8859\_10\_encoded
|
94
|
+
* be\_iso8859\_10\_encoded
|
95
|
+
* be\_iso\_8859\_11\_encoded
|
96
|
+
* be\_iso8859\_11\_encoded
|
97
|
+
* be\_iso\_8859\_13\_encoded
|
98
|
+
* be\_iso8859\_13\_encoded
|
99
|
+
* be\_iso\_8859\_14\_encoded
|
100
|
+
* be\_iso8859\_14\_encoded
|
101
|
+
* be\_iso\_8859\_15\_encoded
|
102
|
+
* be\_iso8859\_15\_encoded
|
103
|
+
* be\_iso\_8859\_16\_encoded
|
104
|
+
* be\_iso8859\_16\_encoded
|
105
|
+
* be\_koi8\_r\_encoded
|
106
|
+
* be\_cp878\_encoded
|
107
|
+
* be\_koi8\_u\_encoded
|
108
|
+
* be\_shift\_jis\_encoded
|
109
|
+
* be\_sjis\_encoded
|
110
|
+
* be\_utf\_16be\_encoded
|
111
|
+
* be\_ucs\_2be\_encoded
|
112
|
+
* be\_utf\_16le\_encoded
|
113
|
+
* be\_utf\_32be\_encoded
|
114
|
+
* be\_ucs\_4be\_encoded
|
115
|
+
* be\_utf\_32le\_encoded
|
116
|
+
* be\_ucs\_4le\_encoded
|
117
|
+
* be\_windows\_1251\_encoded
|
118
|
+
* be\_cp1251\_encoded
|
119
|
+
* be\_ibm437\_encoded
|
120
|
+
* be\_cp437\_encoded
|
121
|
+
* be\_ibm737\_encoded
|
122
|
+
* be\_cp737\_encoded
|
123
|
+
* be\_ibm775\_encoded
|
124
|
+
* be\_cp775\_encoded
|
125
|
+
* be\_cp850\_encoded
|
126
|
+
* be\_ibm850\_encoded
|
127
|
+
* be\_ibm852\_encoded
|
128
|
+
* be\_cp852\_encoded
|
129
|
+
* be\_ibm855\_encoded
|
130
|
+
* be\_cp855\_encoded
|
131
|
+
* be\_ibm857\_encoded
|
132
|
+
* be\_cp857\_encoded
|
133
|
+
* be\_ibm860\_encoded
|
134
|
+
* be\_cp860\_encoded
|
135
|
+
* be\_ibm861\_encoded
|
136
|
+
* be\_cp861\_encoded
|
137
|
+
* be\_ibm862\_encoded
|
138
|
+
* be\_cp862\_encoded
|
139
|
+
* be\_ibm863\_encoded
|
140
|
+
* be\_cp863\_encoded
|
141
|
+
* be\_ibm864\_encoded
|
142
|
+
* be\_cp864\_encoded
|
143
|
+
* be\_ibm865\_encoded
|
144
|
+
* be\_cp865\_encoded
|
145
|
+
* be\_ibm866\_encoded
|
146
|
+
* be\_cp866\_encoded
|
147
|
+
* be\_ibm869\_encoded
|
148
|
+
* be\_cp869\_encoded
|
149
|
+
* be\_windows\_1258\_encoded
|
150
|
+
* be\_cp1258\_encoded
|
151
|
+
* be\_gb1988\_encoded
|
152
|
+
* be\_maccenteuro\_encoded
|
153
|
+
* be\_maccroatian\_encoded
|
154
|
+
* be\_maccyrillic\_encoded
|
155
|
+
* be\_macgreek\_encoded
|
156
|
+
* be\_maciceland\_encoded
|
157
|
+
* be\_macroman\_encoded
|
158
|
+
* be\_macromania\_encoded
|
159
|
+
* be\_macthai\_encoded
|
160
|
+
* be\_macturkish\_encoded
|
161
|
+
* be\_macukraine\_encoded
|
162
|
+
* be\_stateless\_iso\_2022\_jp\_encoded
|
163
|
+
* be\_eucjp\_ms\_encoded
|
164
|
+
* be\_euc\_jp\_ms\_encoded
|
165
|
+
* be\_cp51932\_encoded
|
166
|
+
* be\_gb2312\_encoded
|
167
|
+
* be\_euc\_cn\_encoded
|
168
|
+
* be\_euccn\_encoded
|
169
|
+
* be\_gb12345\_encoded
|
170
|
+
* be\_iso\_2022\_jp\_encoded
|
171
|
+
* be\_iso2022\_jp\_encoded
|
172
|
+
* be\_iso\_2022\_jp\_2\_encoded
|
173
|
+
* be\_iso2022\_jp2\_encoded
|
174
|
+
* be\_cp50220\_encoded
|
175
|
+
* be\_cp50221\_encoded
|
176
|
+
* be\_windows\_1252\_encoded
|
177
|
+
* be\_cp1252\_encoded
|
178
|
+
* be\_windows\_1250\_encoded
|
179
|
+
* be\_cp1250\_encoded
|
180
|
+
* be\_windows\_1256\_encoded
|
181
|
+
* be\_cp1256\_encoded
|
182
|
+
* be\_windows\_1253\_encoded
|
183
|
+
* be\_cp1253\_encoded
|
184
|
+
* be\_windows\_1255\_encoded
|
185
|
+
* be\_cp1255\_encoded
|
186
|
+
* be\_windows\_1254\_encoded
|
187
|
+
* be\_cp1254\_encoded
|
188
|
+
* be\_tis\_620\_encoded
|
189
|
+
* be\_windows\_874\_encoded
|
190
|
+
* be\_cp874\_encoded
|
191
|
+
* be\_windows\_1257\_encoded
|
192
|
+
* be\_cp1257\_encoded
|
193
|
+
* be\_windows\_31j\_encoded
|
194
|
+
* be\_cp932\_encoded
|
195
|
+
* be\_cswindows31j\_encoded
|
196
|
+
* be\_macjapanese\_encoded
|
197
|
+
* be\_macjapan\_encoded
|
198
|
+
* be\_utf\_7\_encoded
|
199
|
+
* be\_cp65000\_encoded
|
200
|
+
* be\_utf8\_mac\_encoded
|
201
|
+
* be\_utf\_8\_mac\_encoded
|
202
|
+
* be\_utf\_8\_hfs\_encoded
|
203
|
+
* be\_utf8\_docomo\_encoded
|
204
|
+
* be\_sjis\_docomo\_encoded
|
205
|
+
* be\_utf8\_kddi\_encoded
|
206
|
+
* be\_sjis\_kddi\_encoded
|
207
|
+
* be\_iso\_2022\_jp\_kddi\_encoded
|
208
|
+
* be\_stateless\_iso\_2022\_jp\_kddi\_encoded
|
209
|
+
* be\_utf8\_softbank\_encoded
|
210
|
+
* be\_sjis\_softbank\_encoded
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module RSpecEncodingMatchers
|
2
|
+
extend RSpec::Matchers::DSL
|
3
|
+
|
4
|
+
matcher :be_encoded_as do |expected|
|
5
|
+
match do |actual|
|
6
|
+
actual.encoding == Encoding.find(expected.to_s)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Encoding.list.each do |encoding|
|
11
|
+
encoding.names.each do |name|
|
12
|
+
|
13
|
+
matcher "be_#{name.gsub("-", "_").downcase}_encoded".to_sym do
|
14
|
+
match { |actual| actual.encoding == encoding }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rspec_encoding_matchers/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rspec-encoding-matchers"
|
7
|
+
s.version = RSpecEncodingMatchers::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jeff Pollard"]
|
10
|
+
s.email = ["jeff.pollard@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{RSpec matchers for Ruby 1.9 string encodings.}
|
13
|
+
s.description = %q{RSpec matchers for Ruby 1.9 string encodings.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "rspec-encoding-matchers"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'ZenTest'
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "#be_encoded_as" do
|
6
|
+
|
7
|
+
it "matches encoding of strings with official names" do
|
8
|
+
"hello".should be_encoded_as("UTF-8")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "matches encoding of strings alised to the actual encoding" do
|
12
|
+
"hello".should be_encoded_as("CP65001")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "matches encodings found with symbols" do
|
16
|
+
"hello".should be_encoded_as(:CP65001)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
Encoding.list.each do |encoding|
|
22
|
+
encoding.names.each do |name|
|
23
|
+
|
24
|
+
matcher_name = "be_#{name.gsub("-", "_").downcase}_encoded"
|
25
|
+
|
26
|
+
describe "##{matcher_name}" do
|
27
|
+
|
28
|
+
it "matches stings in the requested encoding" do
|
29
|
+
"hello".encode(encoding).should send(matcher_name) unless encoding.dummy?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-encoding-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Pollard
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-21 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: ZenTest
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
description: RSpec matchers for Ruby 1.9 string encodings.
|
50
|
+
email:
|
51
|
+
- jeff.pollard@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .autotest
|
60
|
+
- .gitignore
|
61
|
+
- .rspec
|
62
|
+
- .rvmrc
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/rspec_encoding_matchers.rb
|
67
|
+
- lib/rspec_encoding_matchers/version.rb
|
68
|
+
- rspec-encoding-matchers.gemspec
|
69
|
+
- spec/encoding_matcher_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: ""
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: -2940195445060341523
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: -2940195445060341523
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: rspec-encoding-matchers
|
101
|
+
rubygems_version: 1.5.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: RSpec matchers for Ruby 1.9 string encodings.
|
105
|
+
test_files:
|
106
|
+
- spec/encoding_matcher_spec.rb
|
107
|
+
- spec/spec_helper.rb
|