spec_support 0.0.9 → 0.0.10

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.rdoc CHANGED
@@ -56,3 +56,14 @@ is a combined function that executes
56
56
 
57
57
  shown above as valid_attributes on a ActiveRecord model
58
58
  (typically produced with FactoryGirl)
59
+
60
+ == has_query_params?
61
+
62
+ in a spec do:
63
+
64
+ class String
65
+ include SpecSupport::QueryParams
66
+ end
67
+
68
+ URI.unescape(rendered).should have_query_params(
69
+ "f[key][]", "value+with+spaces")
@@ -0,0 +1,14 @@
1
+ module SpecSupport
2
+ module QueryParams
3
+
4
+ def has_query_params?(k,v)
5
+ return false unless k && k.match(/[^\s]/)
6
+ k_esc = Regexp.escape(k)
7
+ v_esc = Regexp.escape(v)
8
+ r = Regexp.new("(^|&|&|[?])#{k_esc}=#{v_esc}($|&|&|\")")
9
+ r.match(self)
10
+ end
11
+
12
+ end
13
+ end
14
+
@@ -1,3 +1,3 @@
1
1
  module SpecSupport
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/spec_support.rb CHANGED
@@ -6,5 +6,6 @@ module SpecSupport
6
6
 
7
7
  require 'check_all_columns'
8
8
  require 'delete_nil_values'
9
+ require 'query_params'
9
10
 
10
11
  end
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  describe "present_attributes" do
24
24
 
25
- it "yields a non_nil values" do
25
+ it "yields all non_nil values" do
26
26
  m = OpenStruct.new(:attributes => {:a => 'c', :b => nil})
27
27
  SpecSupport.present_attributes(m).should == {:a => 'c'}
28
28
  end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe "has_query_params?" do
5
+
6
+ before(:all) do
7
+ class TestForSpecSupport < String
8
+ include SpecSupport::QueryParams
9
+ end
10
+ end
11
+
12
+ it "does not have empty key-value pair" do
13
+ t = TestForSpecSupport.new("key=value")
14
+ t.has_query_params?(nil,nil).should be_false
15
+ end
16
+
17
+ it "has simple key-value pair" do
18
+ t = TestForSpecSupport.new("key=value")
19
+ t.has_query_params?("key", "value").should be_true
20
+ end
21
+
22
+ it "does not match subpart of value" do
23
+ t = TestForSpecSupport.new("key=values")
24
+ t.has_query_params?("key", "value").should be_false
25
+ end
26
+
27
+ it "does not match subpart of key" do
28
+ t = TestForSpecSupport.new("skey=value")
29
+ t.has_query_params?("key", "value").should be_false
30
+ end
31
+
32
+ it "does not match subpart of value delimited by &" do
33
+ t = TestForSpecSupport.new("key=values&")
34
+ t.has_query_params?("key", "value").should be_false
35
+ end
36
+
37
+ it "does match value delimited by &" do
38
+ t = TestForSpecSupport.new("key=value&a=b")
39
+ t.has_query_params?("key", "value").should be_true
40
+ end
41
+
42
+ it "does not match subpart of key delimited by &" do
43
+ t = TestForSpecSupport.new("&skey=values")
44
+ t.has_query_params?("key", "value").should be_false
45
+ end
46
+
47
+ it "does match key delimited by &" do
48
+ t = TestForSpecSupport.new("a=b&key=value")
49
+ t.has_query_params?("key", "value").should be_true
50
+ end
51
+
52
+ it "does not match subpart of value delimited by &amp;" do
53
+ t = TestForSpecSupport.new("key=values&amp;")
54
+ t.has_query_params?("key", "value").should be_false
55
+ end
56
+
57
+ it "does match value delimited by &amp;" do
58
+ t = TestForSpecSupport.new("key=value&amp;a=b")
59
+ t.has_query_params?("key", "value").should be_true
60
+ end
61
+
62
+ it "does not match subpart of key delimited by &amp;" do
63
+ t = TestForSpecSupport.new("&amp;skey=values")
64
+ t.has_query_params?("key", "value").should be_false
65
+ end
66
+
67
+ it "does match key delimited by &amp;" do
68
+ t = TestForSpecSupport.new("a=b&amp;key=value")
69
+ t.has_query_params?("key", "value").should be_true
70
+ end
71
+
72
+ it "does not match subpart of value delimited by \"" do
73
+ t = TestForSpecSupport.new("key=values\"")
74
+ t.has_query_params?("key", "value").should be_false
75
+ end
76
+
77
+ it "does match value delimited by \"" do
78
+ t = TestForSpecSupport.new("key=value\"")
79
+ t.has_query_params?("key", "value").should be_true
80
+ end
81
+
82
+ it "does not match subpart of key delimited by ?" do
83
+ t = TestForSpecSupport.new("?skey=values")
84
+ t.has_query_params?("key", "value").should be_false
85
+ end
86
+
87
+ it "does match key delimited by ?" do
88
+ t = TestForSpecSupport.new("?key=value")
89
+ t.has_query_params?("key", "value").should be_true
90
+ end
91
+
92
+ it "does match with regexp special chars" do
93
+ t = TestForSpecSupport.new("key=val-+{ue")
94
+ t.has_query_params?("key", "val-+{ue").should be_true
95
+ end
96
+
97
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spec_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -34,17 +34,19 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
- - lib/spec_support/version.rb
38
37
  - lib/spec_support/check_all_columns.rb
38
+ - lib/spec_support/query_params.rb
39
+ - lib/spec_support/version.rb
39
40
  - lib/spec_support/delete_nil_values.rb
40
41
  - lib/spec_support.rb
41
42
  - lib/tasks/spec_support_tasks.rake
42
43
  - MIT-LICENSE
43
44
  - Rakefile
44
45
  - README.rdoc
45
- - spec/spec_helper.rb
46
- - spec/delete_nil_values_spec.rb
47
46
  - spec/file_spec.rb
47
+ - spec/delete_nil_values_spec.rb
48
+ - spec/query_params_spec.rb
49
+ - spec/spec_helper.rb
48
50
  homepage: http://github.com/petervandenabeele/spec_support
49
51
  licenses: []
50
52
  post_install_message:
@@ -59,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
61
  version: '0'
60
62
  segments:
61
63
  - 0
62
- hash: 577299729
64
+ hash: -512570605
63
65
  required_rubygems_version: !ruby/object:Gem::Requirement
64
66
  none: false
65
67
  requirements:
@@ -68,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
70
  version: '0'
69
71
  segments:
70
72
  - 0
71
- hash: 577299729
73
+ hash: -512570605
72
74
  requirements: []
73
75
  rubyforge_project:
74
76
  rubygems_version: 1.8.23
@@ -76,6 +78,7 @@ signing_key:
76
78
  specification_version: 3
77
79
  summary: spec/support for common cases
78
80
  test_files:
79
- - spec/spec_helper.rb
80
- - spec/delete_nil_values_spec.rb
81
81
  - spec/file_spec.rb
82
+ - spec/delete_nil_values_spec.rb
83
+ - spec/query_params_spec.rb
84
+ - spec/spec_helper.rb