negative-method 0.1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/lib/negative_method.rb +22 -0
- data/list/.gitignore +3 -0
- data/list/Gemfile +4 -0
- data/list/Rakefile +2 -0
- data/list/lib/list.rb +3 -0
- data/list/lib/list/version.rb +3 -0
- data/list/list.gemspec +21 -0
- data/negative-method.gemspec +13 -9
- data/spec/negative-method_spec.rb +41 -0
- metadata +19 -13
- data/lib/negative-method.rb +0 -0
- data/test/helper.rb +0 -18
- data/test/test_negative-method.rb +0 -7
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem
|
9
|
+
gem 'rspec', '1.3.1'
|
10
10
|
gem "bundler", "~> 1.0.0"
|
11
11
|
gem "jeweler", "~> 1.5.1"
|
12
12
|
gem "rcov", ">= 0"
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ GEM
|
|
8
8
|
rake
|
9
9
|
rake (0.8.7)
|
10
10
|
rcov (0.9.9)
|
11
|
-
|
11
|
+
rspec (1.3.1)
|
12
12
|
|
13
13
|
PLATFORMS
|
14
14
|
ruby
|
@@ -17,7 +17,7 @@ DEPENDENCIES
|
|
17
17
|
bundler (~> 1.0.0)
|
18
18
|
jeweler (~> 1.5.1)
|
19
19
|
rcov
|
20
|
-
|
20
|
+
rspec (= 1.3.1)
|
21
21
|
|
22
22
|
METADATA
|
23
23
|
version: 1.0.6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.1.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module NegativeMethod
|
2
|
+
def method_missing(negative_method_name, *args)
|
3
|
+
method = get_original_method negative_method_name.to_s
|
4
|
+
if (method)
|
5
|
+
if self.respond_to?(method)
|
6
|
+
return !self.send(method, *args)
|
7
|
+
else
|
8
|
+
raise "Cannot call negative method #{negative_method_name}, original method undefined"
|
9
|
+
end
|
10
|
+
else
|
11
|
+
super;
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_original_method method_name
|
16
|
+
if method_name.match(/^not_/) || method_name.match(/_not_/)
|
17
|
+
return method_name.sub(/not_/,'')
|
18
|
+
elsif method_name.match(/_not$/) || method_name.match(/_not?/)
|
19
|
+
return method_name.sub(/_not/,'')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/list/.gitignore
ADDED
data/list/Gemfile
ADDED
data/list/Rakefile
ADDED
data/list/lib/list.rb
ADDED
data/list/list.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "list/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "list"
|
7
|
+
s.version = List::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["TODO: Write your name"]
|
10
|
+
s.email = ["TODO: Write your email address"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{TODO: Write a gem summary}
|
13
|
+
s.description = %q{TODO: Write a gem description}
|
14
|
+
|
15
|
+
s.rubyforge_project = "list"
|
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
|
+
end
|
data/negative-method.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{negative-method}
|
8
|
-
s.version = "
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Vinh Tran"]
|
@@ -24,10 +24,15 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.rdoc",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
-
"lib/
|
27
|
+
"lib/negative_method.rb",
|
28
|
+
"list/.gitignore",
|
29
|
+
"list/Gemfile",
|
30
|
+
"list/Rakefile",
|
31
|
+
"list/lib/list.rb",
|
32
|
+
"list/lib/list/version.rb",
|
33
|
+
"list/list.gemspec",
|
28
34
|
"negative-method.gemspec",
|
29
|
-
"
|
30
|
-
"test/test_negative-method.rb"
|
35
|
+
"spec/negative-method_spec.rb"
|
31
36
|
]
|
32
37
|
s.homepage = %q{http://github.com/vinhtiensinh/negative-method}
|
33
38
|
s.licenses = ["MIT"]
|
@@ -35,8 +40,7 @@ Gem::Specification.new do |s|
|
|
35
40
|
s.rubygems_version = %q{1.3.7}
|
36
41
|
s.summary = %q{generate negative methods base on existing positive method, if you have object.good? you will automatically have object.not_good?}
|
37
42
|
s.test_files = [
|
38
|
-
"
|
39
|
-
"test/test_negative-method.rb"
|
43
|
+
"spec/negative-method_spec.rb"
|
40
44
|
]
|
41
45
|
|
42
46
|
if s.respond_to? :specification_version then
|
@@ -44,18 +48,18 @@ Gem::Specification.new do |s|
|
|
44
48
|
s.specification_version = 3
|
45
49
|
|
46
50
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_development_dependency(%q<
|
51
|
+
s.add_development_dependency(%q<rspec>, ["= 1.3.1"])
|
48
52
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
50
54
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
55
|
else
|
52
|
-
s.add_dependency(%q<
|
56
|
+
s.add_dependency(%q<rspec>, ["= 1.3.1"])
|
53
57
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
58
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
55
59
|
s.add_dependency(%q<rcov>, [">= 0"])
|
56
60
|
end
|
57
61
|
else
|
58
|
-
s.add_dependency(%q<
|
62
|
+
s.add_dependency(%q<rspec>, ["= 1.3.1"])
|
59
63
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
64
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
61
65
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'lib/negative_method'
|
2
|
+
|
3
|
+
class TestClass
|
4
|
+
include NegativeMethod
|
5
|
+
end
|
6
|
+
|
7
|
+
describe NegativeMethod do
|
8
|
+
it "should raise error if the method is undefined" do
|
9
|
+
test = TestClass.new
|
10
|
+
lambda { test.hasNotBeenDefined }.should raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise error if the original method is undefined" do
|
14
|
+
test = TestClass.new
|
15
|
+
lambda { test.not_defined }.should raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should negate method start with 'not_'" do
|
19
|
+
test = TestClass.new
|
20
|
+
test.should_receive(:valid).and_return(true)
|
21
|
+
test.not_valid.should == false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should negate method with '_not_' in the middle of the method name" do
|
25
|
+
test = TestClass.new
|
26
|
+
test.should_receive(:is_valid).and_return(true)
|
27
|
+
test.is_not_valid.should == false
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should negate method with '_not' at the end" do
|
31
|
+
test = TestClass.new
|
32
|
+
test.should_receive(:is).with('valid').and_return(true)
|
33
|
+
test.is_not('valid').should == false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should negate method with '_not?' at the end" do
|
37
|
+
test = TestClass.new
|
38
|
+
test.should_receive(:has?).with('element').and_return(true)
|
39
|
+
test.has_not?('element').should == false
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: negative-method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
-
|
7
|
+
- 1
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
version:
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vinh Tran
|
@@ -23,13 +23,15 @@ dependencies:
|
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - "="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 25
|
29
29
|
segments:
|
30
|
-
-
|
31
|
-
|
32
|
-
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
- 1
|
33
|
+
version: 1.3.1
|
34
|
+
name: rspec
|
33
35
|
requirement: *id001
|
34
36
|
type: :development
|
35
37
|
- !ruby/object:Gem::Dependency
|
@@ -95,10 +97,15 @@ files:
|
|
95
97
|
- README.rdoc
|
96
98
|
- Rakefile
|
97
99
|
- VERSION
|
98
|
-
- lib/
|
100
|
+
- lib/negative_method.rb
|
101
|
+
- list/.gitignore
|
102
|
+
- list/Gemfile
|
103
|
+
- list/Rakefile
|
104
|
+
- list/lib/list.rb
|
105
|
+
- list/lib/list/version.rb
|
106
|
+
- list/list.gemspec
|
99
107
|
- negative-method.gemspec
|
100
|
-
-
|
101
|
-
- test/test_negative-method.rb
|
108
|
+
- spec/negative-method_spec.rb
|
102
109
|
has_rdoc: true
|
103
110
|
homepage: http://github.com/vinhtiensinh/negative-method
|
104
111
|
licenses:
|
@@ -134,5 +141,4 @@ signing_key:
|
|
134
141
|
specification_version: 3
|
135
142
|
summary: generate negative methods base on existing positive method, if you have object.good? you will automatically have object.not_good?
|
136
143
|
test_files:
|
137
|
-
-
|
138
|
-
- test/test_negative-method.rb
|
144
|
+
- spec/negative-method_spec.rb
|
data/lib/negative-method.rb
DELETED
File without changes
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'negative-method'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|