must 0.2.1 → 0.2.2

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.
data/README CHANGED
@@ -15,7 +15,7 @@ Testing Methods
15
15
  ===============
16
16
 
17
17
  be : check whether object equals to the argument
18
- kind_of : check whether object is a kind of the argument
18
+ kind_of : check whether object is a kind of the arguments
19
19
  coerced : check whether object can be coerced to the argument
20
20
  blank : check whether object is blank?
21
21
  exist : check whether object is not nil (NOTE: false is ok)
@@ -62,6 +62,9 @@ false.must.exist # => false
62
62
  [].must.be.kind_of(Integer, Array) # => []
63
63
  1.must.be.kind_of(String, Array) # Must::Invalid: expected String/Array but got Fixnum
64
64
 
65
+ # must(*args) is a syntax sugar for kind_of
66
+ 1.must(Integer) # same as "1.must.be.kind_of(Integer)"
67
+
65
68
  # coercing : looks like kind_of except converting its value if possible
66
69
  1.must.be.coerced(Integer, String => proc{|val| val.to_i}) # => 1
67
70
  "1".must.be.coerced(Integer, String => proc{|val| val.to_i}) # => 1
data/Rakefile CHANGED
@@ -1,48 +1,22 @@
1
- require 'rubygems'
2
- require 'rake/gempackagetask'
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
3
4
 
4
- GEM_NAME = "must"
5
- AUTHOR = "maiha"
6
- EMAIL = "maiha@wota.jp"
7
- HOMEPAGE = "http://github.com/maiha/must"
8
- SUMMARY = "constraint plugin"
9
- GEM_VERSION = "0.2.1"
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
10
7
 
11
- spec = Gem::Specification.new do |s|
12
- s.rubyforge_project = 'asakusarb'
13
- s.executables = []
14
- s.name = GEM_NAME
15
- s.version = GEM_VERSION
16
- s.platform = Gem::Platform::RUBY
17
- s.has_rdoc = true
18
- s.extra_rdoc_files = ["README"]
19
- s.summary = SUMMARY
20
- s.description = s.summary
21
- s.author = AUTHOR
22
- s.email = EMAIL
23
- s.homepage = HOMEPAGE
24
- s.require_path = 'lib'
25
- s.files = %w(README Rakefile) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
8
+ desc 'Test the must plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
26
13
  end
27
14
 
28
- Rake::GemPackageTask.new(spec) do |pkg|
29
- pkg.gem_spec = spec
15
+ desc 'Generate documentation for the must plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Must'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
30
22
  end
31
-
32
- desc "Install the gem"
33
- task :install do
34
- Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
35
- end
36
-
37
- desc "Uninstall the gem"
38
- task :uninstall do
39
- Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
40
- end
41
-
42
- desc "Create a gemspec file"
43
- task :gemspec do
44
- File.open("#{GEM_NAME}.gemspec", "w") do |file|
45
- file.puts spec.to_ruby
46
- end
47
- end
48
-
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Include hook code here
2
+
3
+ require File.dirname(__FILE__) + '/lib/must'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/must.rb CHANGED
@@ -3,8 +3,12 @@ module Must
3
3
  class Invalid < StandardError; end
4
4
  class ShouldNotEmpty < Invalid; end
5
5
 
6
- def must
7
- Rule.new(self)
6
+ def must(*args)
7
+ if args.size > 0
8
+ Rule.new(self).be.kind_of(*args)
9
+ else
10
+ Rule.new(self)
11
+ end
8
12
  end
9
13
  end
10
14
 
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :must do
3
+ # # Task goes here
4
+ # end
data/test/must_test.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require File.join(File.dirname(__FILE__), '../init')
4
+
5
+ class MustTest < Test::Unit::TestCase
6
+
7
+ def test_must_be
8
+ assert_nothing_raised {1.must.be 1}
9
+ assert_nothing_raised {[1,2,3].must.be [1,2,3]}
10
+ assert_nothing_raised {{:a=>1, "b"=>2}.must.be({:a=>1, "b"=>2})}
11
+ assert_nothing_raised {String.must.be String}
12
+ end
13
+
14
+ def test_must_be_error
15
+ assert_raises(Invalid) {1.must.be 2}
16
+ end
17
+
18
+ def test_must_be_with_block
19
+ assert_equal :error, 1.must.be(2) {:error}
20
+ end
21
+
22
+ def test_must_not_be_blank
23
+ if Object.instance_methods.include?("blank?")
24
+ assert_equal "ok", "ok".must.not.be.blank
25
+ assert_equal "ok", "ok".must.not.be.blank {"ng"}
26
+ assert_equal "ng", "".must.not.be.blank {"ng"}
27
+ assert_raises(Invalid) {"".must.not.be.blank}
28
+ end
29
+ end
30
+
31
+ def test_must_accepts_args_as_kind_of
32
+ assert_equal "ok", "ok".must(String)
33
+ assert_raises(Invalid) {"ok".must(Integer)}
34
+ assert_equal "ok", "ok".must(Integer, String)
35
+ end
36
+ end
37
+
38
+
39
+ class CoercedTest < Test::Unit::TestCase
40
+ def test_is_a_feature
41
+ assert_equal 1, 1.must.be.coerced(Integer)
42
+ assert_equal 1, 1.must.be.coerced(Integer, String)
43
+ assert_equal 1, 1.must.be.coerced(String, Numeric)
44
+
45
+ assert_raises(Invalid) { "1".must.be.coerced(Integer) }
46
+ assert_raises(Invalid) { "1".must.be.coerced(Integer, Range) }
47
+ assert_raises(NotImplementedError) { "1".must.be.coerced(Integer){raise NotImplementedError} }
48
+ end
49
+
50
+ def test_coecing_succeeded
51
+ assert_equal 1, 1.must.be.coerced(Integer, String=>proc{|i|i.to_i})
52
+ assert_equal 1, "1".must.be.coerced(Integer, String=>proc{|i|i.to_i})
53
+ assert_equal 1, "1".must.be.coerced(Integer, String=>proc{|i|i.to_i}, Range=>proc{|i|i.first})
54
+ assert_equal 1, "1".must.be.coerced(Integer, Range, String=>proc{|i|i.to_i}, Range=>proc{|i|i.first})
55
+ assert_equal 1, "1".must.be.coerced(File, Integer, Range, String=>proc{|i|i.to_i}, Range=>proc{|i|i.first})
56
+ end
57
+
58
+ def test_coecing_failed
59
+ assert_raises(Invalid) { "1".must.be.coerced(Integer, String=>proc{|i| /a/}) }
60
+ assert_raises(NotImplementedError) { "1".must.be.coerced(Integer, String=>proc{|i| /a/}){raise NotImplementedError} }
61
+ end
62
+
63
+ def test_cascaded_coecing_succeeded
64
+ assert_equal 1, 1.must.be.coerced(Integer, Symbol=>:to_s, String=>:to_i)
65
+ assert_equal 1, "1".must.be.coerced(Integer, Symbol=>:to_s, String=>:to_i)
66
+ assert_equal 1, :"1".must.be.coerced(Integer, Symbol=>:to_s, String=>:to_i)
67
+ end
68
+
69
+ def test_detect_livelock
70
+ assert_raises(Invalid){ "1".must.be.coerced(Integer, Symbol=>:to_s, String=>:intern)}
71
+ assert_raises(Invalid){:"1".must.be.coerced(Integer, Symbol=>:to_s, String=>:intern)}
72
+ end
73
+
74
+ end
75
+
76
+
77
+ class MatchTest < Test::Unit::TestCase
78
+ def test_match_range
79
+ # succeeded
80
+ assert_equal 1, 1.must.match(0..3)
81
+ assert_equal 'b', 'b'.must.match('a'..'c')
82
+
83
+ # failed
84
+ assert_raises(Invalid) { 1.must.match(2..3) }
85
+ assert_raises(Invalid) { 'a'.must.match('y'..'z') }
86
+ end
87
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: must
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,23 +15,27 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-07 00:00:00 +09:00
18
+ date: 2012-01-25 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: constraint plugin
22
+ description: ""
23
23
  email: maiha@wota.jp
24
24
  executables: []
25
25
 
26
26
  extensions: []
27
27
 
28
- extra_rdoc_files:
29
- - README
28
+ extra_rdoc_files: []
29
+
30
30
  files:
31
31
  - README
32
32
  - Rakefile
33
- - lib/must/rule.rb
33
+ - init.rb
34
+ - install.rb
34
35
  - lib/must.rb
36
+ - lib/must/rule.rb
37
+ - tasks/expectation_tasks.rake
38
+ - test/must_test.rb
35
39
  has_rdoc: true
36
40
  homepage: http://github.com/maiha/must
37
41
  licenses: []
@@ -61,10 +65,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
65
  version: "0"
62
66
  requirements: []
63
67
 
64
- rubyforge_project: asakusarb
68
+ rubyforge_project:
65
69
  rubygems_version: 1.3.7
66
70
  signing_key:
67
71
  specification_version: 3
68
- summary: constraint plugin
72
+ summary: ""
69
73
  test_files: []
70
74