wrong 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/README.markdown +3 -1
  2. data/lib/wrong.rb +2 -1
  3. data/lib/wrong/chunk.rb +6 -1
  4. data/lib/wrong/irb.rb +16 -0
  5. data/lib/wrong/version.rb +1 -1
  6. data/test/adapters/rspec_test.rb +4 -2
  7. data/test/assert_test.rb +1 -1
  8. data/test/suite.rb +1 -1
  9. data/test/test_helper.rb +8 -1
  10. metadata +10 -69
  11. data/lib/predicated/Gemfile +0 -15
  12. data/lib/predicated/LICENSE +0 -20
  13. data/lib/predicated/README.markdown +0 -191
  14. data/lib/predicated/Rakefile +0 -51
  15. data/lib/predicated/lib/predicated.rb +0 -4
  16. data/lib/predicated/lib/predicated/autogen_call.rb +0 -37
  17. data/lib/predicated/lib/predicated/constrain.rb +0 -66
  18. data/lib/predicated/lib/predicated/evaluate.rb +0 -94
  19. data/lib/predicated/lib/predicated/from/callable_object.rb +0 -108
  20. data/lib/predicated/lib/predicated/from/json.rb +0 -59
  21. data/lib/predicated/lib/predicated/from/ruby_code_string.rb +0 -73
  22. data/lib/predicated/lib/predicated/from/url_part.rb +0 -104
  23. data/lib/predicated/lib/predicated/from/xml.rb +0 -61
  24. data/lib/predicated/lib/predicated/gem_check.rb +0 -34
  25. data/lib/predicated/lib/predicated/predicate.rb +0 -111
  26. data/lib/predicated/lib/predicated/print.rb +0 -62
  27. data/lib/predicated/lib/predicated/selectable.rb +0 -102
  28. data/lib/predicated/lib/predicated/simple_templated_predicate.rb +0 -79
  29. data/lib/predicated/lib/predicated/string_utils.rb +0 -20
  30. data/lib/predicated/lib/predicated/to/arel.rb +0 -41
  31. data/lib/predicated/lib/predicated/to/json.rb +0 -48
  32. data/lib/predicated/lib/predicated/to/sentence.rb +0 -94
  33. data/lib/predicated/lib/predicated/to/solr.rb +0 -15
  34. data/lib/predicated/lib/predicated/to/xml.rb +0 -67
  35. data/lib/predicated/lib/predicated/version.rb +0 -3
  36. data/lib/predicated/predicated.gemspec +0 -22
  37. data/lib/predicated/test/autogen_call_test.rb +0 -40
  38. data/lib/predicated/test/canonical_transform_cases.rb +0 -63
  39. data/lib/predicated/test/constrain_test.rb +0 -86
  40. data/lib/predicated/test/enumerable_test.rb +0 -32
  41. data/lib/predicated/test/equality_test.rb +0 -32
  42. data/lib/predicated/test/evaluate_test.rb +0 -149
  43. data/lib/predicated/test/from/callable_object_canonical_test.rb +0 -43
  44. data/lib/predicated/test/from/callable_object_test.rb +0 -78
  45. data/lib/predicated/test/from/json_test.rb +0 -83
  46. data/lib/predicated/test/from/ruby_code_string_canonical_test.rb +0 -37
  47. data/lib/predicated/test/from/ruby_code_string_test.rb +0 -103
  48. data/lib/predicated/test/from/url_part_parser_test.rb +0 -123
  49. data/lib/predicated/test/from/url_part_test.rb +0 -48
  50. data/lib/predicated/test/from/xml_test.rb +0 -57
  51. data/lib/predicated/test/json_conversion_test.rb +0 -33
  52. data/lib/predicated/test/print_test.rb +0 -66
  53. data/lib/predicated/test/selectable_test.rb +0 -123
  54. data/lib/predicated/test/simple_templated_predicate_test.rb +0 -39
  55. data/lib/predicated/test/suite.rb +0 -2
  56. data/lib/predicated/test/test_helper.rb +0 -64
  57. data/lib/predicated/test/test_helper_with_wrong.rb +0 -6
  58. data/lib/predicated/test/to/arel_test.rb +0 -85
  59. data/lib/predicated/test/to/json_test.rb +0 -74
  60. data/lib/predicated/test/to/sentence_test.rb +0 -90
  61. data/lib/predicated/test/to/solr_test.rb +0 -39
  62. data/lib/predicated/test/to/xml_test.rb +0 -72
  63. data/lib/predicated/test/xml_conversion_test.rb +0 -34
  64. data/lib/predicated/test_integration/arel_integration_test.rb +0 -52
  65. data/lib/predicated/test_integration/canonical_integration_cases.rb +0 -66
  66. data/lib/predicated/test_integration/schema.xml +0 -83
  67. data/lib/predicated/test_integration/solr_integration_test.rb +0 -71
  68. data/lib/predicated/test_integration/sqlite_db +0 -0
  69. data/lib/predicated/test_integration/suite.rb +0 -2
  70. data/lib/predicated/test_integration/usage_test.rb +0 -252
data/README.markdown CHANGED
@@ -110,7 +110,9 @@ So wait a second. How do we do it? Doesn't Ruby have [poor support for AST intro
110
110
  Before you get your knickers in a twist about how this is totally unacceptable because it doesn't support this or that use case, here are our caveats and excuses:
111
111
 
112
112
  * It works! Tested in 1.8.6, 1.8.7, 1.9.1, and 1.9.2-rc2. (Thank you, [rvm](http://rvm.beginrescueend.com/)!)
113
- * Your code needs to be in a file. That means it doesn't work in IRB. (If you're developing Ruby code without saving it to a mounted disk, then sorry, Wrong is not right for you.)
113
+ * Your code needs to be in a file.
114
+ * If you're developing Ruby code without saving it to a mounted disk, then sorry, Wrong is not right for you.
115
+ * We monkey-patch IRB so if you do `irb -rwrong` it'll save off your session in a place Wrong can read it.
114
116
  * It's a development-time testing library, not a production runtime library, so there are no security or filesystem issues.
115
117
  * `eval` isn't evil, it's just misunderstood.
116
118
  * It makes a few assumptions about the structure of your code, leading to some restrictions:
data/lib/wrong.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require "predicated/lib/predicated"
3
2
 
3
+ require "predicated"
4
4
  require "wrong/assert"
5
5
  require "wrong/chunk"
6
6
  require "wrong/sexp_ext"
7
7
  require "wrong/version"
8
8
  require "wrong/config"
9
+ require "wrong/irb"
data/lib/wrong/chunk.rb CHANGED
@@ -39,7 +39,12 @@ module Wrong
39
39
  # if not, then glom the next line and try again
40
40
  # repeat until it parses or we're out of lines
41
41
  def parse
42
- lines = File.read(@file).split("\n")
42
+ source = if @file == "(irb)"
43
+ IRB.CurrentContext.all_lines
44
+ else
45
+ File.read(@file)
46
+ end
47
+ lines = source.split("\n")
43
48
  @parser ||= RubyParser.new
44
49
  @chunk = nil
45
50
  c = 0
data/lib/wrong/irb.rb ADDED
@@ -0,0 +1,16 @@
1
+ if defined? IRB
2
+ module IRB
3
+ class Context
4
+ alias :original_evaluate :evaluate
5
+ attr_reader :all_lines
6
+
7
+ def evaluate(line, line_no)
8
+ (@all_lines ||= "") <<line
9
+ original_evaluate line, line_no
10
+ end
11
+ end
12
+ end
13
+
14
+ # include it in the top level too, since if you're using Wrong inside IRB that's probably what you want
15
+ include Wrong::Assert
16
+ end
data/lib/wrong/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wrong
2
- VERSION = "0.3.1" unless defined?(Wrong::VERSION)
2
+ VERSION = "0.3.2" unless defined?(Wrong::VERSION)
3
3
  end
@@ -1,8 +1,10 @@
1
1
  require "./test/test_helper"
2
- require "wrong/adapters/rspec"
3
2
 
4
3
  describe "testing rspec" do
5
4
  it "works" do
5
+
6
+ require "wrong/adapters/rspec" # if we don't require this in here, then it interferes with minitest
7
+
6
8
  # I would use
7
9
  # out, err = capturing(:stdout, :stderr) do
8
10
  # but minitest does its own arcane stream munging and it's not working
@@ -35,7 +37,7 @@ inside rspec land
35
37
  failures = Spec::Runner.options.reporter.instance_variable_get(:@failures) # todo: use my own reporter?
36
38
  assert !failures.empty?
37
39
  exception = failures.first.exception
38
- assert(exception.is_a? Spec::Expectations::ExpectationNotMetError)
40
+ assert(exception.is_a?(Spec::Expectations::ExpectationNotMetError))
39
41
  assert(exception.message == "Expected (sky == \"green\"), but \"blue\" is not equal to \"green\"\n sky is \"blue\"\n")
40
42
  end
41
43
  end
data/test/assert_test.rb CHANGED
@@ -52,7 +52,7 @@ describe "basic assert features" do
52
52
 
53
53
  it "gives a meaningful error when passed no block" do
54
54
  e = get_error {
55
- @m.assert (2+2 == 5)
55
+ @m.assert(2+2 == 5)
56
56
  }
57
57
  assert e.message =~ /a block/
58
58
  end
data/test/suite.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  #simple way to make sure requires are isolated
2
- result = Dir["test/**/*_test.rb"].collect{|test_file| system("ruby #{test_file}") }.uniq == [true]
2
+ result = Dir["test/**/*_test.rb"].collect{|test_file| system("bundle exec ruby #{test_file}") }.uniq == [true]
3
3
  puts "suite " + (result ? "passed" : "FAILED")
4
4
  exit(result ? 0 : 1)
data/test/test_helper.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift "#{dir}/../lib"
3
- $LOAD_PATH.unshift "../predicated/lib" if File.exist?("../predicated/lib")
3
+
4
+ predicated_project_dir = File.expand_path("../predicated")
5
+ if File.exist?(predicated_project_dir) # if predicated project is a sibling of this project
6
+ puts "using predicated from #{predicated_project_dir}"
7
+ $LOAD_PATH.unshift "#{predicated_project_dir}/lib"
8
+ require "predicated"
9
+ end
10
+
4
11
  require "rubygems"
5
12
  require "minitest/spec"
6
13
  require "minitest/unit"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrong
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Conover
@@ -16,12 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-29 00:00:00 -07:00
19
+ date: 2010-09-22 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: ParseTree
24
- prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -34,10 +33,10 @@ dependencies:
34
33
  - 5
35
34
  version: 3.0.5
36
35
  type: :runtime
36
+ prerelease: false
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: ruby_parser
40
- prerelease: false
41
40
  requirement: &id002 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
@@ -50,10 +49,10 @@ dependencies:
50
49
  - 4
51
50
  version: 2.0.4
52
51
  type: :runtime
52
+ prerelease: false
53
53
  version_requirements: *id002
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: ruby2ruby
56
- prerelease: false
57
56
  requirement: &id003 !ruby/object:Gem::Requirement
58
57
  none: false
59
58
  requirements:
@@ -66,10 +65,10 @@ dependencies:
66
65
  - 4
67
66
  version: 1.2.4
68
67
  type: :runtime
68
+ prerelease: false
69
69
  version_requirements: *id003
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: diff
72
- prerelease: false
73
72
  requirement: &id004 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
@@ -82,10 +81,10 @@ dependencies:
82
81
  - 6
83
82
  version: 0.3.6
84
83
  type: :runtime
84
+ prerelease: false
85
85
  version_requirements: *id004
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: diff-lcs
88
- prerelease: false
89
88
  requirement: &id005 !ruby/object:Gem::Requirement
90
89
  none: false
91
90
  requirements:
@@ -98,6 +97,7 @@ dependencies:
98
97
  - 2
99
98
  version: 1.1.2
100
99
  type: :runtime
100
+ prerelease: false
101
101
  version_requirements: *id005
102
102
  description: |-
103
103
  Wrong provides a general assert method that takes a predicate block. Assertion failure
@@ -113,66 +113,6 @@ extensions: []
113
113
  extra_rdoc_files:
114
114
  - README.markdown
115
115
  files:
116
- - lib/predicated/Gemfile
117
- - lib/predicated/lib/predicated/autogen_call.rb
118
- - lib/predicated/lib/predicated/constrain.rb
119
- - lib/predicated/lib/predicated/evaluate.rb
120
- - lib/predicated/lib/predicated/from/callable_object.rb
121
- - lib/predicated/lib/predicated/from/json.rb
122
- - lib/predicated/lib/predicated/from/ruby_code_string.rb
123
- - lib/predicated/lib/predicated/from/url_part.rb
124
- - lib/predicated/lib/predicated/from/xml.rb
125
- - lib/predicated/lib/predicated/gem_check.rb
126
- - lib/predicated/lib/predicated/predicate.rb
127
- - lib/predicated/lib/predicated/print.rb
128
- - lib/predicated/lib/predicated/selectable.rb
129
- - lib/predicated/lib/predicated/simple_templated_predicate.rb
130
- - lib/predicated/lib/predicated/string_utils.rb
131
- - lib/predicated/lib/predicated/to/arel.rb
132
- - lib/predicated/lib/predicated/to/json.rb
133
- - lib/predicated/lib/predicated/to/sentence.rb
134
- - lib/predicated/lib/predicated/to/solr.rb
135
- - lib/predicated/lib/predicated/to/xml.rb
136
- - lib/predicated/lib/predicated/version.rb
137
- - lib/predicated/lib/predicated.rb
138
- - lib/predicated/LICENSE
139
- - lib/predicated/predicated.gemspec
140
- - lib/predicated/Rakefile
141
- - lib/predicated/README.markdown
142
- - lib/predicated/test/autogen_call_test.rb
143
- - lib/predicated/test/canonical_transform_cases.rb
144
- - lib/predicated/test/constrain_test.rb
145
- - lib/predicated/test/enumerable_test.rb
146
- - lib/predicated/test/equality_test.rb
147
- - lib/predicated/test/evaluate_test.rb
148
- - lib/predicated/test/from/callable_object_canonical_test.rb
149
- - lib/predicated/test/from/callable_object_test.rb
150
- - lib/predicated/test/from/json_test.rb
151
- - lib/predicated/test/from/ruby_code_string_canonical_test.rb
152
- - lib/predicated/test/from/ruby_code_string_test.rb
153
- - lib/predicated/test/from/url_part_parser_test.rb
154
- - lib/predicated/test/from/url_part_test.rb
155
- - lib/predicated/test/from/xml_test.rb
156
- - lib/predicated/test/json_conversion_test.rb
157
- - lib/predicated/test/print_test.rb
158
- - lib/predicated/test/selectable_test.rb
159
- - lib/predicated/test/simple_templated_predicate_test.rb
160
- - lib/predicated/test/suite.rb
161
- - lib/predicated/test/test_helper.rb
162
- - lib/predicated/test/test_helper_with_wrong.rb
163
- - lib/predicated/test/to/arel_test.rb
164
- - lib/predicated/test/to/json_test.rb
165
- - lib/predicated/test/to/sentence_test.rb
166
- - lib/predicated/test/to/solr_test.rb
167
- - lib/predicated/test/to/xml_test.rb
168
- - lib/predicated/test/xml_conversion_test.rb
169
- - lib/predicated/test_integration/arel_integration_test.rb
170
- - lib/predicated/test_integration/canonical_integration_cases.rb
171
- - lib/predicated/test_integration/schema.xml
172
- - lib/predicated/test_integration/solr_integration_test.rb
173
- - lib/predicated/test_integration/sqlite_db
174
- - lib/predicated/test_integration/suite.rb
175
- - lib/predicated/test_integration/usage_test.rb
176
116
  - lib/wrong/adapters/minitest.rb
177
117
  - lib/wrong/adapters/rspec.rb
178
118
  - lib/wrong/adapters/test_unit.rb
@@ -180,6 +120,7 @@ files:
180
120
  - lib/wrong/chunk.rb
181
121
  - lib/wrong/close_to.rb
182
122
  - lib/wrong/config.rb
123
+ - lib/wrong/irb.rb
183
124
  - lib/wrong/message/array_diff.rb
184
125
  - lib/wrong/message/string_diff.rb
185
126
  - lib/wrong/message/test_context.rb
@@ -1,15 +0,0 @@
1
- source :gemcutter
2
- gem "ruby_parser"
3
- gem "ruby2ruby"
4
- gem "ParseTree"
5
- gem "diff"
6
- gem "diff-lcs"
7
- gem "minitest"
8
- gem "nokogiri"
9
- gem "arel", "~>0.4"
10
- gem "sqlite3-ruby"
11
- gem "activerecord", "~>3.0.0.beta"
12
- gem "i18n"
13
- gem "json", "1.1.9"
14
- gem "treetop", "~>1.4.8"
15
-
@@ -1,20 +0,0 @@
1
- Copyright (c) 2010 Steve Conover
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,191 +0,0 @@
1
- ## Abstract ##
2
-
3
- Predicated is a simple predicate model for Ruby. It provides useful predicate transformations and operations.
4
-
5
- Tracker project:
6
- [http://www.pivotaltracker.com/projects/95014](http://www.pivotaltracker.com/projects/95014)
7
-
8
- ## Transformations ##
9
-
10
- - From:
11
- - json
12
- - xml
13
- - url part, ex: "!(a=1&b=2|c=3)"
14
- - callable objects (lambdas/procs, and therefore blocks) - ruby 1.8.x only
15
- - ruby code - ruby 1.8.x only
16
- - To:
17
- - json
18
- - xml
19
- - sql where clause via [arel](http://github.com/rails/arel)
20
- - [solr](http://lucene.apache.org/solr/) query string
21
- - english sentence, ex: "'a' is not equal to 'b'"
22
-
23
- ## Usage ##
24
-
25
- Note: The test suite acts as a comprehensive usage guide.
26
-
27
-
28
- Evaluate a predicate:
29
-
30
- require "predicated/evaluate"
31
- include Predicated
32
-
33
- Predicate { Eq(1, 2) }.evaluate == false
34
- Predicate { Lt(1, 2) }.evaluate == true
35
- Predicate { Or(Lt(1, 2),Eq(1, 2)) }.evaluate == true
36
-
37
- x = 1
38
- Predicate { Lt(x, 2) }.evaluate == true
39
-
40
-
41
- Parse a predicate from part of a url and then turn it into a sql where clause:
42
-
43
- require "predicated/from/url_part"
44
- require "predicated/to/arel"
45
-
46
- predicate = Predicated::Predicate.from_url_part("(color=red|color=green)&size=large")
47
-
48
- predicate.inspect ==
49
- "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
50
-
51
- predicate.to_arel(Table(:shirt)).to_sql ==
52
- %{(("shirt"."color" = 'red' OR "shirt"."color" = 'green') AND "shirt"."size" = 'large')}
53
-
54
-
55
- Parse a predicate from json and then turn it into a solr query string:
56
-
57
- require "predicated/from/json"
58
- require "predicated/to/solr"
59
-
60
- predicate = Predicated::Predicate.from_json_str(%{
61
- {"and":[{"or":[["color","==","red"],["color","==","green"]]},["size","==","large"]]}
62
- })
63
-
64
- predicate.inspect == "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
65
-
66
- predicate.to_solr == "((color:red OR color:green) AND size:large)"
67
-
68
-
69
- From json:
70
-
71
- require "predicated/from/json"
72
-
73
- Predicated::Predicate.from_json_str(%{
74
- {"and":[
75
- {"or":[
76
- ["color","==","red"],
77
- ["color","==","green"]
78
- ]},
79
- ["size","==","large"]
80
- ]}
81
- }).inspect == "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
82
-
83
-
84
- From xml:
85
-
86
- require "predicated/from/xml"
87
-
88
- Predicated::Predicate.from_xml(%{
89
- <and>
90
- <or>
91
- <equal><left>color</left><right>red</right></equal>
92
- <equal><left>color</left><right>green</right></equal>
93
- </or>
94
- <equal><left>size</left><right>large</right></equal>
95
- </and>
96
- }).inspect == "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
97
-
98
-
99
- From url part:
100
-
101
- require "predicated/from/url_part"
102
-
103
- Predicated::Predicate.from_url_part("(color=red|color=green)&size=large").inspect ==
104
- "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
105
-
106
-
107
- From callable object:
108
-
109
- require "predicated/from/callable_object"
110
-
111
- Predicated::Predicate.from_callable_object{('color'=='red' || 'color'=='green') && 'size'=='large'}.inspect ==
112
- "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
113
-
114
-
115
- From ruby code string:
116
-
117
- require "predicated/from/ruby_code_string"
118
-
119
- Predicated::Predicate.from_ruby_code_string("('color'=='red' || 'color'=='green') && 'size'=='large'").inspect ==
120
- "And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))"
121
-
122
-
123
- To json:
124
-
125
- require "predicated/to/json"
126
- include Predicated
127
-
128
- Predicate{And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))}.to_json_str ==
129
- %{
130
- {"and":[
131
- {"or":[
132
- ["color","==","red"],
133
- ["color","==","green"]
134
- ]},
135
- ["size","==","large"]
136
- ]}
137
- }
138
-
139
-
140
- To xml:
141
-
142
- require "predicated/to/xml"
143
- include Predicated
144
-
145
- Predicate{And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))}.to_xml ==
146
- %{
147
- <and>
148
- <or>
149
- <equal><left>color</left><right>red</right></equal>
150
- <equal><left>color</left><right>green</right></equal>
151
- </or>
152
- <equal><left>size</left><right>large</right></equal>
153
- </and>
154
- }
155
-
156
-
157
- To arel (sql where clause):
158
-
159
- require "predicated/to/arel"
160
- include Predicated
161
-
162
- Predicate{And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))}.to_arel(Table(:shirt)).to_sql ==
163
- %{(("shirt"."color" = 'red' OR "shirt"."color" = 'green') AND "shirt"."size" = 'large')}
164
-
165
-
166
- To solr query string:
167
-
168
- require "predicated/to/solr"
169
- include Predicated
170
-
171
- Predicate{And(Or(Eq('color','red'),Eq('color','green')),Eq('size','large'))}.to_solr ==
172
- "((color:red OR color:green) AND size:large)"
173
-
174
-
175
- To sentence:
176
-
177
- require "predicated/to/sentence"
178
- include Predicated
179
-
180
- Predicate{ And(Eq("a",1),Eq("b",2)) }.to_sentence ==
181
- "'a' is equal to 1 and 'b' is equal to 2"
182
-
183
- Predicate{ Gt("a",1) }.to_negative_sentence ==
184
- "'a' is not greater than 1"
185
-
186
-
187
- ## Testing Notes ##
188
-
189
- Right now this project makes use of Wrong for assertions. Wrong uses this project. It's kind of neat in an eat-your-own-dogfood sense, but it's possible that this will be problematic over time (particularly when changes in this project cause assertions to behave differently - if even temporarily).
190
-
191
- A middle ground is to make "from ruby string" and "from callable object" use minitest asserts, since these are the "interesting" parts of Predicated relied on by Wrong.