inquisitive 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class StringTest < Test
4
+
5
+ def string
6
+ Inquisitive::String.new @raw_string
7
+ end
8
+
9
+ include StringTests
10
+
11
+ end
@@ -0,0 +1,151 @@
1
+ require 'test_helper'
2
+
3
+ class InquisitiveTest < Test
4
+ Helpers = Module.new.extend Inquisitive
5
+ HashWithIndifferentAccess ||= Inquisitive::HashWithIndifferentAccess
6
+
7
+ def setup
8
+ super
9
+ @symbol = :a
10
+ @numeric = 1
11
+ @class = if Object.const_defined?(:Misc)
12
+ Misc
13
+ else
14
+ Object.const_set(:Misc, Class.new)
15
+ end
16
+ @object = @class.new
17
+ end
18
+
19
+ ####
20
+ # CONVERSION
21
+ ##
22
+ def test_converted_nil_equality
23
+ assert_equal Inquisitive[nil], nil
24
+ end
25
+ def test_converted_false_equality
26
+ assert_equal Inquisitive[false], false
27
+ end
28
+ def test_converted_true_equality
29
+ assert_equal Inquisitive[true], true
30
+ end
31
+ def test_converted_numeric_equality
32
+ assert_equal Inquisitive[@numeric], @numeric
33
+ end
34
+ def test_converted_symbol_equality
35
+ assert_equal Inquisitive[@symbol], @symbol
36
+ end
37
+ def test_converted_class_equality
38
+ assert_equal Inquisitive[@class], @class
39
+ end
40
+ def test_converted_object_equality
41
+ assert_equal Inquisitive[@object], @object
42
+ end
43
+
44
+ def test_converted_string_instanciation
45
+ assert_instance_of Inquisitive::String, Inquisitive[@raw_string]
46
+ end
47
+ def test_converted_string_equality
48
+ assert_equal Inquisitive[@raw_string], @raw_string
49
+ end
50
+
51
+ def test_converted_array_instanciation
52
+ assert_instance_of Inquisitive::Array, Inquisitive[@raw_array]
53
+ end
54
+ def test_converted_array_equality
55
+ assert_equal Inquisitive[@raw_array], @raw_array
56
+ end
57
+
58
+ def test_converted_hash_instanciation
59
+ assert_instance_of Inquisitive::Hash, Inquisitive[@raw_hash]
60
+ end
61
+ def test_converted_hash_equality
62
+ assert_equal Inquisitive[@raw_hash], HashWithIndifferentAccess.new(@raw_hash)
63
+ end
64
+
65
+ ####
66
+ # PRESENCE
67
+ ##
68
+ def test_presence_of_nil
69
+ refute Inquisitive.present? nil
70
+ end
71
+ def test_presence_of_false
72
+ refute Inquisitive.present? false
73
+ end
74
+ def test_presence_of_true
75
+ assert Inquisitive.present? true
76
+ end
77
+ def test_presence_of_numeric
78
+ assert Inquisitive.present? @numeric
79
+ end
80
+ def test_presence_of_symbol
81
+ assert Inquisitive.present? @symbol
82
+ end
83
+ def test_presence_of_class
84
+ assert Inquisitive.present? @class
85
+ end
86
+ def test_presence_of_object
87
+ assert Inquisitive.present? @object
88
+ end
89
+
90
+ def test_presence_of_non_blank_strings
91
+ assert Inquisitive.present? @raw_string
92
+ end
93
+ def test_presence_of_blank_strings
94
+ refute Inquisitive.present? ""
95
+ end
96
+
97
+ def test_presence_of_non_empty_arrays
98
+ assert Inquisitive.present? @raw_array
99
+ end
100
+ def test_presence_of_partially_empty_string_array_elements
101
+ assert Inquisitive.present? [nil, @raw_string]
102
+ end
103
+ def test_presence_of_partially_empty_hash_array_elements
104
+ assert Inquisitive.present? [nil, @raw_string]
105
+ end
106
+ def test_presence_of_empty_array_elements
107
+ refute Inquisitive.present? [nil, "", [], {a: nil}]
108
+ end
109
+ def test_presence_of_empty_arrays
110
+ refute Inquisitive.present? []
111
+ end
112
+
113
+ def test_presence_of_non_empty_hashes
114
+ assert Inquisitive.present? @raw_hash
115
+ end
116
+ def test_presence_of_partially_empty_string_hash_elements
117
+ assert Inquisitive.present?({a: nil, b: @raw_string})
118
+ end
119
+ def test_presence_of_partially_empty_array_hash_elements
120
+ assert Inquisitive.present?({a: nil, b: @raw_array})
121
+ end
122
+ def test_presence_of_empty_hash_elements
123
+ refute Inquisitive.present?({a: nil, b: "", c: [], d: {a: nil}})
124
+ end
125
+ def test_presence_of_empty_hashes
126
+ refute Inquisitive.present?({})
127
+ end
128
+
129
+ ####
130
+ # HELPERS
131
+ ##
132
+ def test_found_symbol_predicate_method_helper
133
+ assert Helpers.send :predicate_method?, :foo?
134
+ end
135
+ def test_found_string_predicate_method_helper
136
+ assert Helpers.send :predicate_method?, "foo?"
137
+ end
138
+ def test_missing_symbol_predicate_method_helper
139
+ refute Helpers.send :predicate_method?, :foo
140
+ end
141
+ def test_missing_string_predicate_method_helper
142
+ refute Helpers.send :predicate_method?, "foo"
143
+ end
144
+
145
+ def test_symbol_predication_helper
146
+ assert_equal Helpers.send(:predication, :foo?), 'foo'
147
+ end
148
+ def test_string_predication_helper
149
+ assert_equal Helpers.send(:predication, "foo?"), 'foo'
150
+ end
151
+ end
@@ -0,0 +1,32 @@
1
+ module ArrayTests
2
+ def test_array_value_type
3
+ assert_instance_of Inquisitive::Array, array
4
+ end
5
+ def test_array_match
6
+ assert array.postgres?
7
+ end
8
+ def test_array_miss
9
+ refute array.sql_server?
10
+ end
11
+ def test_array_negative_match
12
+ assert array.exclude.sql_server?
13
+ end
14
+ def test_array_negative_miss
15
+ refute array.exclude.postgres?
16
+ end
17
+ def test_array_double_negative_match
18
+ assert array.exclude.exclude.postgres?
19
+ end
20
+ def test_array_double_negative_miss
21
+ refute array.exclude.exclude.sql_server?
22
+ end
23
+ def test_array_missing_question_mark
24
+ assert_raises(NoMethodError) { array.postgres }
25
+ end
26
+ def test_array_respond_to
27
+ assert_respond_to array, :postgres?
28
+ end
29
+ def test_array_method_missing
30
+ assert_raises(NoMethodError) { array.undefined }
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module CombinatorialEnvironmentTests
2
+
3
+ def test_type_is_parsed_correctly
4
+ assert_kind_of(
5
+ Object.const_get(:"#{@type.capitalize}"),
6
+ App.send(@type)
7
+ )
8
+ end
9
+
10
+ def test_type_is_converted_correctly
11
+ assert_kind_of(
12
+ Inquisitive.const_get(:"#{@type.capitalize}"),
13
+ App.send(@type)
14
+ )
15
+ end
16
+
17
+ def test_changing_variable_after_definition
18
+ App.inquires_about @type.upcase, mode: @mode, with: :precache
19
+ test = @mode.static? ? :assert_equal : :refute_equal
20
+ precache = App.precache
21
+ send :"change_#{@type}_variable"
22
+ send test, App.send(@type), precache
23
+ end
24
+
25
+ def test_changing_variable_after_invocation
26
+ test = @mode.dynamic? ? :assert_change : :refute_change
27
+ monitor = -> { App.send(@type) }
28
+ send test, monitor do
29
+ send :"change_#{@type}_variable"
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,26 @@
1
+ module HashTests
2
+ def test_hash_match
3
+ assert hash.authentication?
4
+ end
5
+ def test_hash_miss
6
+ refute hash.registration?
7
+ end
8
+ def test_hash_negative_match
9
+ assert hash.no.registration?
10
+ end
11
+ def test_hash_negative_miss
12
+ refute hash.no.authentication?
13
+ end
14
+ def test_hash_double_negative_match
15
+ assert hash.no.no.authentication?
16
+ end
17
+ def test_hash_double_negative_miss
18
+ refute hash.no.no.registration?
19
+ end
20
+ def test_hash_respond_to
21
+ assert_respond_to hash, :authentication?
22
+ end
23
+ def test_hash_method_missing
24
+ assert_raises(NoMethodError) { hash.undefined }
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module StringTests
2
+ def test_string_value_type
3
+ assert_instance_of Inquisitive::String, string
4
+ end
5
+ def test_string_match
6
+ assert string.production?
7
+ end
8
+ def test_string_miss
9
+ refute string.development?
10
+ end
11
+ def test_string_negative_match
12
+ assert string.not.development?
13
+ end
14
+ def test_string_negative_miss
15
+ refute string.not.production?
16
+ end
17
+ def test_string_double_negative_match
18
+ assert string.not.not.production?
19
+ end
20
+ def test_string_double_negative_miss
21
+ refute string.not.not.development?
22
+ end
23
+ def test_string_missing_question_mark
24
+ assert_raises(NoMethodError) { string.production }
25
+ end
26
+ def test_string_respond_to
27
+ assert_respond_to string, :development?
28
+ end
29
+ def test_string_method_missing
30
+ assert_raises(NoMethodError) { string.undefined }
31
+ end
32
+ end
@@ -0,0 +1,67 @@
1
+ require "rubygems"
2
+ require "simplecov"
3
+ require "minitest/autorun"
4
+
5
+ SimpleCov.start do
6
+ add_filter "/test"
7
+ end
8
+
9
+ class Test < MiniTest::Test
10
+
11
+ def assert_change(lambda_getter)
12
+ old = lambda_getter.call
13
+ yield
14
+ refute_equal old, lambda_getter.call
15
+ end
16
+
17
+ def refute_change(lambda_getter)
18
+ old = lambda_getter.call
19
+ yield
20
+ assert_equal old, lambda_getter.call
21
+ end
22
+
23
+ def refute_raise
24
+ nothing_raised = true
25
+ message = 'Nothing raised.'
26
+ begin
27
+ yield
28
+ rescue => e
29
+ nothing_raised = false
30
+ message = "Expected nothing to be raised, caught: #{e.exception}:\n" \
31
+ "#{e.backtrace.join("\n")}"
32
+ end
33
+ assert nothing_raised, message
34
+ end
35
+
36
+ def setup
37
+ @raw_string = 'production'
38
+ @raw_array = %w[mysql postgres sqlite]
39
+ @raw_hash = {
40
+ authentication: true,
41
+ in: @raw_string,
42
+ databases: @raw_array
43
+ }
44
+ end
45
+
46
+ end
47
+
48
+ class EnvironmentTest < Test
49
+
50
+ def setup
51
+ super
52
+ Object.const_set :App, Module.new
53
+ App.extend Inquisitive::Environment
54
+ end
55
+ def teardown
56
+ super
57
+ Object.send :remove_const, :App
58
+ end
59
+
60
+ end
61
+
62
+ require "shared/string_tests"
63
+ require "shared/array_tests"
64
+ require "shared/hash_tests"
65
+ require "shared/combinatorial_environment_tests"
66
+
67
+ require "inquisitive"
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inquisitive
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Keele
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ description: Predicate methods for those curious about their datastructures.
70
+ email:
71
+ - dev@chriskeele.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.md
79
+ - README.md
80
+ - Rakefile
81
+ - inquisitive.gemspec
82
+ - lib/inquisitive.rb
83
+ - lib/inquisitive/array.rb
84
+ - lib/inquisitive/environment.rb
85
+ - lib/inquisitive/hash.rb
86
+ - lib/inquisitive/hash_with_indifferent_access.rb
87
+ - lib/inquisitive/string.rb
88
+ - test/inquisitive/array_test.rb
89
+ - test/inquisitive/combinatorial_environment_test.rb
90
+ - test/inquisitive/environment_test.rb
91
+ - test/inquisitive/hash_test.rb
92
+ - test/inquisitive/hash_with_indifferent_access_test.rb
93
+ - test/inquisitive/string_test.rb
94
+ - test/inquisitive_test.rb
95
+ - test/shared/array_tests.rb
96
+ - test/shared/combinatorial_environment_tests.rb
97
+ - test/shared/hash_tests.rb
98
+ - test/shared/string_tests.rb
99
+ - test/test_helper.rb
100
+ homepage: https://github.com/rawsugar/inquisitive
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Predicate methods for those curious about their datastructures.
124
+ test_files:
125
+ - test/inquisitive/array_test.rb
126
+ - test/inquisitive/combinatorial_environment_test.rb
127
+ - test/inquisitive/environment_test.rb
128
+ - test/inquisitive/hash_test.rb
129
+ - test/inquisitive/hash_with_indifferent_access_test.rb
130
+ - test/inquisitive/string_test.rb
131
+ - test/inquisitive_test.rb
132
+ - test/shared/array_tests.rb
133
+ - test/shared/combinatorial_environment_tests.rb
134
+ - test/shared/hash_tests.rb
135
+ - test/shared/string_tests.rb
136
+ - test/test_helper.rb