jnunemaker-crack 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,14 +2,30 @@
2
2
 
3
3
  Really simple JSON and XML parsing, ripped from Merb and Rails. The XML parser is ripped from Merb and the JSON parser is ripped from Rails. I take no credit, just packaged them for all to enjoy and easily use.
4
4
 
5
- = usage
5
+ == note on releases
6
+
7
+ Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
8
+
9
+ * rake gemspec
10
+ * gem build httparty.gemspec
11
+ * gem install the gem that was built
12
+
13
+ == note on patches/pull requests
14
+
15
+ * Fork the project.
16
+ * Make your feature addition or bug fix.
17
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
18
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == usage
6
22
 
7
23
  gem 'crack'
8
24
  require 'crack' # for xml and json
9
25
  require 'crack/json' # for just json
10
26
  require 'crack/xml' # for just xml
11
27
 
12
- = examples
28
+ == examples
13
29
 
14
30
  Crack::XML.parse("<tag>This is the contents</tag>")
15
31
  # => {'tag' => 'This is the contents'}
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 3
4
+ :patch: 4
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{crack}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
9
- s.date = %q{2009-06-30}
9
+ s.date = %q{2009-07-19}
10
10
  s.email = %q{nunemaker@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -27,7 +27,9 @@ Gem::Specification.new do |s|
27
27
  "test/crack_test.rb",
28
28
  "test/data/twittersearch-firefox.json",
29
29
  "test/data/twittersearch-ie.json",
30
+ "test/hash_test.rb",
30
31
  "test/json_test.rb",
32
+ "test/string_test.rb",
31
33
  "test/test_helper.rb",
32
34
  "test/xml_test.rb"
33
35
  ]
@@ -40,7 +42,9 @@ Gem::Specification.new do |s|
40
42
  s.summary = %q{Really simple JSON and XML parsing, ripped from Merb and Rails.}
41
43
  s.test_files = [
42
44
  "test/crack_test.rb",
45
+ "test/hash_test.rb",
43
46
  "test/json_test.rb",
47
+ "test/string_test.rb",
44
48
  "test/test_helper.rb",
45
49
  "test/xml_test.rb"
46
50
  ]
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  class Object #:nodoc:
2
4
  # @return <TrueClass, FalseClass>
3
5
  #
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class CrackTest < Test::Unit::TestCase
4
+ context "to_xml_attributes" do
5
+ setup do
6
+ @hash = { :one => "ONE", "two" => "TWO" }
7
+ end
8
+
9
+ should "should turn the hash into xml attributes" do
10
+ attrs = @hash.to_xml_attributes
11
+ attrs.should =~ /one="ONE"/m
12
+ attrs.should =~ /two="TWO"/m
13
+ end
14
+
15
+ should 'should preserve _ in hash keys' do
16
+ attrs = {
17
+ :some_long_attribute => "with short value",
18
+ :crash => :burn,
19
+ :merb => "uses extlib"
20
+ }.to_xml_attributes
21
+
22
+ attrs.should =~ /some_long_attribute="with short value"/
23
+ attrs.should =~ /merb="uses extlib"/
24
+ attrs.should =~ /crash="burn"/
25
+ end
26
+ end
27
+
28
+ context "to_params" do
29
+ {
30
+ { "foo" => "bar", "baz" => "bat" } => "foo=bar&baz=bat",
31
+ { "foo" => [ "bar", "baz" ] } => "foo[]=bar&foo[]=baz",
32
+ { "foo" => [ {"bar" => "1"}, {"bar" => 2} ] } => "foo[][bar]=1&foo[][bar]=2",
33
+ { "foo" => { "bar" => [ {"baz" => 1}, {"baz" => "2"} ] } } => "foo[bar][][baz]=1&foo[bar][][baz]=2",
34
+ { "foo" => {"1" => "bar", "2" => "baz"} } => "foo[1]=bar&foo[2]=baz"
35
+ }.each do |hash, params|
36
+ should "should covert hash: #{hash.inspect} to params: #{params.inspect}" do
37
+ hash.to_params.split('&').sort.should == params.split('&').sort
38
+ end
39
+ end
40
+
41
+ should 'should not leave a trailing &' do
42
+ {
43
+ :name => 'Bob',
44
+ :address => {
45
+ :street => '111 Ruby Ave.',
46
+ :city => 'Ruby Central',
47
+ :phones => ['111-111-1111', '222-222-2222']
48
+ }
49
+ }.to_params.should_not =~ /&$/
50
+ end
51
+
52
+ should 'should URL encode unsafe characters' do
53
+ {:q => "?&\" +"}.to_params.should == "q=%3F%26%22%20%2B"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class CrackTest < Test::Unit::TestCase
4
+ context "snake_case" do
5
+ should "lowercases one word CamelCase" do
6
+ "Merb".snake_case.should == "merb"
7
+ end
8
+
9
+ should "makes one underscore snake_case two word CamelCase" do
10
+ "MerbCore".snake_case.should == "merb_core"
11
+ end
12
+
13
+ should "handles CamelCase with more than 2 words" do
14
+ "SoYouWantContributeToMerbCore".snake_case.should == "so_you_want_contribute_to_merb_core"
15
+ end
16
+
17
+ should "handles CamelCase with more than 2 capital letter in a row" do
18
+ "CNN".snake_case.should == "cnn"
19
+ "CNNNews".snake_case.should == "cnn_news"
20
+ "HeadlineCNNNews".snake_case.should == "headline_cnn_news"
21
+ end
22
+
23
+ should "does NOT change one word lowercase" do
24
+ "merb".snake_case.should == "merb"
25
+ end
26
+
27
+ should "leaves snake_case as is" do
28
+ "merb_core".snake_case.should == "merb_core"
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-crack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-30 00:00:00 -07:00
12
+ date: 2009-07-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,7 +37,9 @@ files:
37
37
  - test/crack_test.rb
38
38
  - test/data/twittersearch-firefox.json
39
39
  - test/data/twittersearch-ie.json
40
+ - test/hash_test.rb
40
41
  - test/json_test.rb
42
+ - test/string_test.rb
41
43
  - test/test_helper.rb
42
44
  - test/xml_test.rb
43
45
  has_rdoc: true
@@ -68,6 +70,8 @@ specification_version: 2
68
70
  summary: Really simple JSON and XML parsing, ripped from Merb and Rails.
69
71
  test_files:
70
72
  - test/crack_test.rb
73
+ - test/hash_test.rb
71
74
  - test/json_test.rb
75
+ - test/string_test.rb
72
76
  - test/test_helper.rb
73
77
  - test/xml_test.rb