ephemeral_response 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,15 @@
1
1
  History
2
2
  =======
3
3
 
4
- 0.2.0 / master
4
+ 0.2.1 / 2010-06-24
5
+ --------------
6
+
7
+ #### Enhancements
8
+
9
+ * Periods no longer replaced with slashes in fixture names.
10
+ * Added skip_expiration option allowing fixtures to never expire.
11
+
12
+ 0.2.0 / 2010-06-23
5
13
  --------------
6
14
 
7
15
  #### Enhancements
@@ -10,9 +18,9 @@ History
10
18
  * Varying POST data and query strings create new fixtures. Previously, GET /
11
19
  and GET /?foo=bar resulted in the same fixture.
12
20
  * Ability to reset configuration with EphemeralResponse::Configuration.reset
13
- * Ability to white list certain hosts. Responses will not be saved for Requests
21
+ * Ability to white list certain hosts. Responses will not be saved for requests
14
22
  made to hosts in the white list.
15
- Use EphemeralResponse::Configuration.white_list = "localhost"
23
+ Use EphemeralResponse::Configuration.white\_list = "localhost"
16
24
  * Ephemeral response prints to the Net/HTTP debugger when establishing a
17
- connection. Just set http.set_debug_output = $stdout to see when Ephemeral
25
+ connection. Set http.set\_debug\_output = $stdout to see when Ephemeral
18
26
  Response connects to a host.
@@ -79,6 +79,19 @@ the local server.
79
79
 
80
80
  EphemeralResponse::Configuration.white_list = "localhost", "smackaho.st"
81
81
 
82
+ Never let fixtures expire by setting skip\_expiration to true.
83
+
84
+ EphemeralResponse::Configuration.skip_expiration = true
85
+
86
+ All together now!
87
+
88
+ EphemeralResponse.configure do |config|
89
+ config.fixture_directory = "test/fixtures/ephemeral_response"
90
+ config.expiration = lambda { one_day * 30 }
91
+ config.white_list = 'localhost'
92
+ config.skip_expiration = true
93
+ end
94
+
82
95
  ## Similar Projects
83
96
  * [Net Recorder](http://github.com/chrisyoung/netrecorder)
84
97
  * [Stalefish](http://github.com/jsmestad/stale_fish)
@@ -96,4 +109,4 @@ the local server.
96
109
 
97
110
  ## Copyright
98
111
 
99
- Copyright (c) 2010 Sandro Turriate. See MIT_LICENSE for details.
112
+ Copyright (c) 2010 Sandro Turriate. See MIT\_LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -7,7 +7,7 @@ require 'ephemeral_response/configuration'
7
7
  require 'ephemeral_response/fixture'
8
8
 
9
9
  module EphemeralResponse
10
- VERSION = "0.2.0".freeze
10
+ VERSION = "0.2.1".freeze
11
11
 
12
12
  def self.activate
13
13
  deactivate
@@ -23,4 +23,13 @@ module EphemeralResponse
23
23
  alias_method(:request, :request_without_ephemeral_response) if method_defined?(:request_without_ephemeral_response)
24
24
  end
25
25
  end
26
+
27
+ def self.fixtures
28
+ Fixture.fixtures
29
+ end
30
+
31
+ def self.configure
32
+ yield Configuration if block_given?
33
+ Configuration
34
+ end
26
35
  end
@@ -2,7 +2,7 @@ module EphemeralResponse
2
2
  module Configuration
3
3
  extend self
4
4
 
5
- attr_writer :fixture_directory
5
+ attr_writer :fixture_directory, :skip_expiration
6
6
 
7
7
  def fixture_directory
8
8
  @fixture_directory || "spec/fixtures/ephemeral_response"
@@ -23,6 +23,11 @@ module EphemeralResponse
23
23
  @expiration = nil
24
24
  @fixture_directory = nil
25
25
  @white_list = nil
26
+ @skip_expiration = nil
27
+ end
28
+
29
+ def skip_expiration
30
+ @skip_expiration || false
26
31
  end
27
32
 
28
33
  def white_list
@@ -60,7 +60,7 @@ module EphemeralResponse
60
60
  end
61
61
 
62
62
  def expired?
63
- (created_at + Configuration.expiration) < Time.now
63
+ !Configuration.skip_expiration && (created_at + Configuration.expiration) < Time.now
64
64
  end
65
65
 
66
66
  def file_name
@@ -76,7 +76,7 @@ module EphemeralResponse
76
76
  end
77
77
 
78
78
  def normalized_name
79
- [uri.host, method, fs_path].compact.join("_").gsub(/[\/.]/, '-')
79
+ [uri.host, method, fs_path].compact.join("_").gsub(/[\/]/, '-')
80
80
  end
81
81
 
82
82
  def fs_path
@@ -39,21 +39,41 @@ describe EphemeralResponse::Configuration do
39
39
  end
40
40
 
41
41
  describe "#reset" do
42
- it "resets expiration, fixture directory, and white list to the defaults" do
43
- subject.fixture_directory = "test/fixtures/ephemeral_response"
42
+ it "resets expiration" do
44
43
  subject.expiration = 1
45
- subject.white_list = 'localhost'
46
- subject.fixture_directory.should == "test/fixtures/ephemeral_response"
47
44
  subject.expiration.should == 1
48
- subject.white_list.should == ['localhost']
45
+ subject.reset
46
+
47
+ subject.expiration.should == 86400
48
+ end
49
49
 
50
+ it "resets fixture_directory" do
51
+ subject.fixture_directory = "test/fixtures/ephemeral_response"
52
+ subject.fixture_directory.should == "test/fixtures/ephemeral_response"
50
53
  subject.reset
51
54
 
52
55
  subject.fixture_directory.should == "spec/fixtures/ephemeral_response"
53
- subject.expiration.should == 86400
56
+ end
57
+
58
+ it "resets white_list" do
59
+ subject.white_list = 'localhost'
60
+ subject.white_list.should == ['localhost']
61
+ subject.reset
62
+
54
63
  subject.white_list.should == []
55
64
  end
56
65
 
66
+ it "resets skip_expiration" do
67
+ subject.skip_expiration = true
68
+ subject.skip_expiration.should == true
69
+ subject.reset
70
+
71
+ subject.skip_expiration.should == false
72
+ end
73
+
74
+ it "resets expiration, fixture directory, expiration, and white list to the defaults" do
75
+ end
76
+
57
77
  it "resets white list after the default has been modified" do
58
78
  subject.white_list << "localhost"
59
79
  subject.reset
@@ -84,4 +104,16 @@ describe EphemeralResponse::Configuration do
84
104
  subject.white_list.should == ['localhost', 'smackaho.st']
85
105
  end
86
106
  end
107
+
108
+ describe "#skip_expiration" do
109
+ it "sets skip_expiration to true" do
110
+ subject.skip_expiration = true
111
+ subject.skip_expiration.should == true
112
+ end
113
+
114
+ it "sets skip_expiration to false" do
115
+ subject.skip_expiration = false
116
+ subject.skip_expiration.should == false
117
+ end
118
+ end
87
119
  end
@@ -276,19 +276,51 @@ describe EphemeralResponse::Fixture do
276
276
  it "chops off the starting slash when accessing '/'" do
277
277
  uri = URI.parse("http://example.com/")
278
278
  fixture = EphemeralResponse::Fixture.new(uri, request)
279
- fixture.file_name.should =~ /example-com_GET_[\w]{7}.yml/
279
+ fixture.file_name.should =~ /example.com_GET_[\w]{7}.yml/
280
280
  end
281
281
 
282
282
  it "chops off the starting slash when accessing '/index.html'" do
283
283
  uri = URI.parse("http://example.com/index.html")
284
284
  fixture = EphemeralResponse::Fixture.new(uri, request)
285
- fixture.file_name.should =~ /example-com_GET_index-html_[\w]{7}.yml/
285
+ fixture.file_name.should =~ /example.com_GET_index.html_[\w]{7}.yml/
286
286
  end
287
287
 
288
288
  it "looks like on longer paths" do
289
289
  uri = URI.parse("http://example.com/users/1/photos/1.html")
290
290
  fixture = EphemeralResponse::Fixture.new(uri, request)
291
- fixture.file_name.should =~ /example-com_GET_users-1-photos-1-html_[\w]{7}.yml/
291
+ fixture.file_name.should =~ /example.com_GET_users-1-photos-1.html_[\w]{7}.yml/
292
+ end
293
+
294
+ describe "#expired?" do
295
+ before do
296
+ fixture
297
+ end
298
+
299
+ context "when expiration isn't skipped" do
300
+ context "when the expiration time has elapsed" do
301
+ it "returns true" do
302
+ Time.travel("2030-01-01") do
303
+ fixture.should be_expired
304
+ end
305
+ end
306
+ end
307
+
308
+ context "when the expiration time has not elapsed" do
309
+ it "returns false" do
310
+ fixture.should_not be_expired
311
+ end
312
+ end
313
+ end
314
+
315
+ context "when expiration is skipped" do
316
+ it "returns false" do
317
+ fixture
318
+ EphemeralResponse::Configuration.skip_expiration = true
319
+ Time.travel("2030-01-01") do
320
+ fixture.should_not be_expired
321
+ end
322
+ end
323
+ end
292
324
  end
293
325
 
294
326
  end
@@ -35,4 +35,25 @@ describe EphemeralResponse do
35
35
  Net::HTTP.instance_methods.should_not include('uri')
36
36
  end
37
37
  end
38
+
39
+ describe ".fixtures" do
40
+ it "returns the registered fixtures" do
41
+ EphemeralResponse.fixtures.should == EphemeralResponse::Fixture.fixtures
42
+ end
43
+ end
44
+
45
+ describe ".configure" do
46
+ it "yields the configuration object when a block is passed" do
47
+ EphemeralResponse.configure {|c| c.expiration = 1}
48
+ EphemeralResponse::Configuration.expiration.should == 1
49
+ end
50
+
51
+ it "returns the configuration object after yielding" do
52
+ EphemeralResponse.configure {}.should == EphemeralResponse::Configuration
53
+ end
54
+
55
+ it "returns the configuration object when no block is present" do
56
+ EphemeralResponse.configure.should == EphemeralResponse::Configuration
57
+ end
58
+ end
38
59
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sandro Turriate
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-23 00:00:00 -04:00
17
+ date: 2010-06-24 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency