sucker 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,26 +42,23 @@ Hit Amazon again.
42
42
 
43
43
  Check the integration specs for more examples.
44
44
 
45
- Testing
46
- -------
45
+ Stubbing
46
+ --------
47
47
 
48
- To fake web requests, create `spec/support/sucker.rb` and:
48
+ To stub web requests in your specs, create `spec/support/sucker_helper.rb`:
49
49
 
50
50
  require "sucker/stub"
51
+
51
52
  Sucker.fixtures_path = File.dirname(__FILE__) + "/../fixtures"
52
53
 
53
- Then, in your spec, stub the worker:
54
+ In your spec, you can now stub the worker:
54
55
 
55
56
  @worker = Sucker.new(some_hash)
56
57
  Sucker.stub(@worker)
57
58
 
58
- The first time you run the spec, Sucker will perform the actual web request and cache the response. Then, it will stub subsequent requests with the cached response.
59
-
60
- Notes
61
- -----
62
-
63
- * The unit specs should run out of the box after you `bundle install`, but the integration specs require you to create [an amazon.yml file with valid credentials](http://github.com/papercavalier/sucker/blob/master/spec/support/amazon.yml.example) in `spec/support`.
59
+ The first time you run the spec, Sucker will perform the actual request. Following requests will use a cached response.
64
60
 
65
- * Version 0.6.0 now has Active Support's Nokogiri-based `to_hash` under the hood. After some meddling, it does what it's supposed to do and is blazing fast. Fix up your code accordingly.
61
+ Compatibility
62
+ -------------
66
63
 
67
- * To test specs against all rubies on your system , run `./rake_rubies.sh spec:progress`.
64
+ Specs pass against Ruby 1.8.7, 1.9.1, 1.9.2, and REE.
@@ -11,8 +11,7 @@ module Sucker
11
11
  end
12
12
 
13
13
  def to_h
14
- doc = Nokogiri::XML(body)
15
- content_to_string(doc.to_hash)
14
+ @hash ||= content_to_string(Nokogiri::XML(body).to_hash)
16
15
  end
17
16
 
18
17
  alias :to_hash :to_h
data/lib/sucker/stub.rb CHANGED
@@ -14,7 +14,13 @@ module Sucker
14
14
  def stub(request)
15
15
  request.instance_eval do
16
16
  self.class.send :define_method, :fixture do
17
- filename = Digest::MD5.hexdigest(host + parameters.values.flatten.join)
17
+ values = parameters.
18
+ reject{ |k, v| %w{AWSAccessKeyId Service}.
19
+ include? k }.
20
+ values.
21
+ flatten.
22
+ join
23
+ filename = Digest::MD5.hexdigest(host + values)
18
24
  "#{Sucker.fixtures_path}/#{filename}.xml"
19
25
  end
20
26
 
@@ -39,6 +39,11 @@ module Sucker
39
39
  @response.to_hash.should eql @response.to_h
40
40
  end
41
41
 
42
+ it "caches hash" do
43
+ hash = @response.to_h
44
+ @response.instance_variable_get(:@hash).should eql hash
45
+ end
46
+
42
47
  it "renders French" do
43
48
  @response.body = "<Title>L'archéologie du savoir</Title>"
44
49
  @response.to_h["Title"].should eql "L'archéologie du savoir"
@@ -39,25 +39,29 @@ module Sucker
39
39
 
40
40
  @worker.get.body.should eql "bar"
41
41
  end
42
+ end
42
43
 
43
- context "defines:" do
44
- context "#fixture" do
45
- it "generates a path for the fixture" do
46
- @worker.fixture.should match /.*\/[0-9a-f]{32}\.xml$/
47
- end
44
+ context "#fixture" do
45
+ it "generates a path for the fixture" do
46
+ @worker.fixture.should match /.*\/[0-9a-f]{32}\.xml$/
47
+ end
48
48
 
49
- it "generates unique fixtures across venues" do
50
- first_fixture = @worker.fixture
51
- @worker.locale = "fr"
52
- @worker.fixture.should_not eql first_fixture
53
- end
49
+ it "generates unique fixtures across venues" do
50
+ first_fixture = @worker.fixture
51
+ @worker.locale = "fr"
52
+ @worker.fixture.should_not eql first_fixture
53
+ end
54
+
55
+ it "generates the same fixture regardless of signature" do
56
+ first_fixture = @worker.fixture
57
+ @worker.stub!(:timestamp).and_return({ "Timestamp" => "foo" })
58
+ @worker.fixture.should eql first_fixture
59
+ end
54
60
 
55
- it "reuses fixture regardless of signature" do
56
- first_fixture = @worker.fixture
57
- @worker.stub!(:timestamp).and_return({ "Timestamp" => "foo" })
58
- @worker.fixture.should eql first_fixture
59
- end
60
- end
61
+ it "generates the same fixture regardless of key" do
62
+ first_fixture = @worker.fixture
63
+ @worker.key = "foo"
64
+ @worker.fixture.should eql first_fixture
61
65
  end
62
66
  end
63
67
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 5
10
- version: 0.6.5
9
+ - 6
10
+ version: 0.6.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hakan Ensari
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-04 00:00:00 +01:00
19
+ date: 2010-08-05 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency