ephemeral_response 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -14,7 +14,6 @@ tmtags
14
14
  *.swp
15
15
 
16
16
  ## PROJECT::GENERAL
17
- .rvmrc
18
17
  coverage
19
18
  rdoc
20
19
  pkg
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use ephemeral_response
@@ -1,14 +1,34 @@
1
1
  History
2
2
  =======
3
3
 
4
+ 0.4.0 / 2011-01-18
5
+ ----------------
6
+
7
+ #### Fixes
8
+
9
+ * Net::HTTP#request now respects the body parameter. When the body
10
+ parameter is passed in, it will be set on the request (like normal)
11
+ making it available for identification of the fixture. (bernerdschaefer,
12
+ veezus)
13
+ * Force removal of expired fixtures to overcome missing file exception
14
+ * Handle fixture load failures by output errant fixture file to debug output
15
+
16
+
17
+ #### Enhancements
18
+
19
+ * EphemeralResponse.fixture\_set allows you to keep named groups of fixtures. By
20
+ default, this is nil (also :default).
21
+ * EphemeralResponse::Configuration.debug\_output prints debugging information to
22
+ the provided IO object
23
+
4
24
  0.3.2 / 2010-07-30
5
25
  ------------------
6
26
 
7
- #### Bug Fix
27
+ #### Fixes
8
28
 
9
- * Net::HTTP.request now yields the response when a fixture exists
29
+ * Net::HTTP#request now yields the response when a fixture exists
10
30
  * Net::HTTPResponse#read\_body works when a fixture exists
11
- * OpenURI compatibility (it depends on #read_body)
31
+ * OpenURI compatibility (it depends on #read\_body)
12
32
 
13
33
  0.3.1 / 2010-06-29
14
34
  --------------
@@ -23,7 +43,7 @@ History
23
43
  #### Enhancements
24
44
 
25
45
  * Periods no longer replaced with slashes in fixture names.
26
- * Added skip_expiration option allowing fixtures to never expire.
46
+ * Added skip\expiration option allowing fixtures to never expire.
27
47
 
28
48
  0.2.0 / 2010-06-23
29
49
  --------------
@@ -93,6 +93,22 @@ An example may help clear this up.
93
93
 
94
94
  Take a look in `examples/custom_cache_key.rb` to see this in action.
95
95
 
96
+ ## Grouping fixtures to isolate responses
97
+
98
+ Occasionally you are in a situation where you are making the same request but
99
+ you are expecting a different result, for example, a list of all resources,
100
+ create a new resource, and then list them again. For this scenario, you can use
101
+ a 'newly_created' fixture set. In your specs, change the fixture set to
102
+ 'newly_created' for the create and second list requests. The default fixture
103
+ set is named :default (or nil).
104
+
105
+ # pseudo code
106
+ get('http://example.com/books').should_not contain('The Illiad')
107
+ EphemeralResponse.fixture_set = :newly_created
108
+ post('http://example.com/books', {:title => 'The Illiad'})
109
+ get('http://example.com/books').should contain('The Illiad')
110
+ EphemeralResponse.fixture_set = :default
111
+
96
112
  ## Configuration
97
113
 
98
114
  Change the fixture directory; defaults to "spec/fixtures/ephemeral\_response"
@@ -114,6 +130,11 @@ Never let fixtures expire by setting skip\_expiration to true.
114
130
 
115
131
  EphemeralResponse::Configuration.skip_expiration = true
116
132
 
133
+ Print debugging information
134
+
135
+ EphemeralResponse::Configuration.debug_output = $stderr
136
+
137
+
117
138
  ### Selenium Tip
118
139
 
119
140
  Always allow requests to be made to a host by adding it to the white list.
@@ -129,6 +150,7 @@ the local server.
129
150
  config.expiration = lambda { one_day * 30 }
130
151
  config.skip_expiration = true
131
152
  config.white_list = 'localhost'
153
+ config.debug_output = $stderr
132
154
  end
133
155
 
134
156
  ## Similar Projects
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ephemeral_response}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sandro Turriate", "Les Hill"]
12
- s.date = %q{2010-07-30}
12
+ s.date = %q{2011-01-18}
13
13
  s.description = %q{
14
14
  Save HTTP responses to give your tests a hint of reality.
15
15
  Responses are saved into your fixtures directory and are used for subsequent web requests until they expire.
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.files = [
22
22
  ".document",
23
23
  ".gitignore",
24
+ ".rvmrc",
24
25
  "Gemfile",
25
26
  "History.markdown",
26
27
  "MIT_LICENSE",
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
36
37
  "lib/ephemeral_response/configuration.rb",
37
38
  "lib/ephemeral_response/fixture.rb",
38
39
  "lib/ephemeral_response/net_http.rb",
40
+ "lib/ephemeral_response/null_output.rb",
39
41
  "lib/ephemeral_response/request.rb",
40
42
  "spec/ephemeral_response/configuration_spec.rb",
41
43
  "spec/ephemeral_response/fixture_spec.rb",
@@ -44,6 +46,7 @@ Gem::Specification.new do |s|
44
46
  "spec/integration/custom_identifier_spec.rb",
45
47
  "spec/integration/normal_flow_spec.rb",
46
48
  "spec/integration/read_body_compatibility_spec.rb",
49
+ "spec/integration/sets_spec.rb",
47
50
  "spec/integration/unique_fixtures_spec.rb",
48
51
  "spec/integration/white_list_spec.rb",
49
52
  "spec/spec.opts",
@@ -66,6 +69,7 @@ Gem::Specification.new do |s|
66
69
  "spec/integration/custom_identifier_spec.rb",
67
70
  "spec/integration/normal_flow_spec.rb",
68
71
  "spec/integration/read_body_compatibility_spec.rb",
72
+ "spec/integration/sets_spec.rb",
69
73
  "spec/integration/unique_fixtures_spec.rb",
70
74
  "spec/integration/white_list_spec.rb",
71
75
  "spec/spec_helper.rb",
@@ -7,9 +7,12 @@ require 'yaml'
7
7
  require 'ephemeral_response/configuration'
8
8
  require 'ephemeral_response/request'
9
9
  require 'ephemeral_response/fixture'
10
+ require 'ephemeral_response/null_output'
10
11
 
11
12
  module EphemeralResponse
12
- VERSION = "0.3.2".freeze
13
+ VERSION = "0.4.0".freeze
14
+
15
+ Error = Class.new(StandardError)
13
16
 
14
17
  def self.activate
15
18
  deactivate
@@ -17,6 +20,20 @@ module EphemeralResponse
17
20
  Fixture.load_all
18
21
  end
19
22
 
23
+ def self.configure
24
+ yield Configuration if block_given?
25
+ Configuration
26
+ end
27
+
28
+ def self.fixture_set
29
+ Configuration.fixture_set
30
+ end
31
+
32
+ def self.fixture_set=(name)
33
+ Configuration.fixture_set = name
34
+ Fixture.load_all
35
+ end
36
+
20
37
  def self.deactivate
21
38
  Net::HTTP.class_eval do
22
39
  remove_method(:generate_uri) if method_defined?(:generate_uri)
@@ -34,8 +51,11 @@ module EphemeralResponse
34
51
  Fixture.fixtures
35
52
  end
36
53
 
37
- def self.configure
38
- yield Configuration if block_given?
39
- Configuration
54
+ # FIXME: Don't deactivate and reactivate, instead set a flag which ignores
55
+ # fixtures entirely.
56
+ def self.live
57
+ deactivate
58
+ yield
59
+ activate
40
60
  end
41
61
  end
@@ -2,12 +2,34 @@ module EphemeralResponse
2
2
  module Configuration
3
3
  extend self
4
4
 
5
+ attr_accessor :fixture_set
5
6
  attr_writer :fixture_directory, :skip_expiration
6
7
 
8
+ def effective_directory
9
+ if fixture_set.nil? or fixture_set.to_s == 'default'
10
+ fixture_directory
11
+ else
12
+ File.join(fixture_directory, fixture_set.to_s)
13
+ end
14
+ end
15
+
7
16
  def fixture_directory
8
17
  @fixture_directory || "spec/fixtures/ephemeral_response"
9
18
  end
10
19
 
20
+ # Set an IO object to receive the debugging information.
21
+ def debug_output=(io)
22
+ if io.respond_to?(:puts)
23
+ @debug_output = io
24
+ else
25
+ raise Error, 'The debug_output object must respond to #puts'
26
+ end
27
+ end
28
+
29
+ def debug_output
30
+ @debug_output ||= NullOutput.new
31
+ end
32
+
11
33
  def expiration=(expiration)
12
34
  if expiration.is_a?(Proc)
13
35
  expiration = instance_eval &expiration
@@ -28,11 +50,13 @@ module EphemeralResponse
28
50
  end
29
51
 
30
52
  def reset
53
+ @fixture_set = nil
31
54
  @expiration = nil
32
55
  @fixture_directory = nil
33
56
  @white_list = nil
34
57
  @skip_expiration = nil
35
58
  @host_registry = nil
59
+ @debug_output = nil
36
60
  end
37
61
 
38
62
  def skip_expiration
@@ -17,14 +17,18 @@ module EphemeralResponse
17
17
 
18
18
  def self.load_all
19
19
  clear
20
- if File.directory?(Configuration.fixture_directory)
21
- Dir.glob("#{Configuration.fixture_directory}/*.yml", &method(:load_fixture))
20
+ if File.directory?(Configuration.effective_directory)
21
+ Dir.glob("#{Configuration.effective_directory}/*.yml", &method(:load_fixture))
22
22
  end
23
23
  fixtures
24
24
  end
25
25
 
26
26
  def self.load_fixture(file_name)
27
- register YAML.load_file(file_name)
27
+ if fixture = YAML.load_file(file_name)
28
+ register fixture
29
+ else
30
+ EphemeralResponse::Configuration.debug_output.puts "EphemeralResponse couldn't load fixture: #{file_name}"
31
+ end
28
32
  end
29
33
 
30
34
  def self.find_or_initialize(uri, request, &block)
@@ -33,7 +37,7 @@ module EphemeralResponse
33
37
 
34
38
  def self.register(fixture)
35
39
  if fixture.expired?
36
- FileUtils.rm fixture.path
40
+ FileUtils.rm_f fixture.path
37
41
  else
38
42
  fixtures[fixture.identifier] = fixture
39
43
  end
@@ -87,18 +91,19 @@ module EphemeralResponse
87
91
  end
88
92
 
89
93
  def path
90
- File.join(Configuration.fixture_directory, file_name)
94
+ File.join(Configuration.effective_directory, file_name)
91
95
  end
92
96
 
93
97
  def register
94
98
  unless Configuration.white_list.include? uri.host
99
+ EphemeralResponse::Configuration.debug_output.puts "#{request.method} #{uri} saved as #{path}"
95
100
  save
96
101
  self.class.register self
97
102
  end
98
103
  end
99
104
 
100
105
  def save
101
- FileUtils.mkdir_p Configuration.fixture_directory
106
+ FileUtils.mkdir_p Configuration.effective_directory
102
107
  File.open(path, 'w') do |f|
103
108
  f.write to_yaml
104
109
  end
@@ -10,7 +10,6 @@ module Net
10
10
  private :connect
11
11
 
12
12
  def do_start_with_ephemeral_response
13
- D "EphemeralResponse: establishing connection to #{uri}"
14
13
  connect_without_ephemeral_response
15
14
  @started = true
16
15
  end
@@ -23,9 +22,10 @@ module Net
23
22
 
24
23
  def request(request, body = nil, &block)
25
24
  generate_uri(request)
25
+ request.set_body_internal body
26
26
  EphemeralResponse::Fixture.respond_to(uri, request, block) do
27
27
  do_start_with_ephemeral_response
28
- request_without_ephemeral_response(request, body, &block)
28
+ request_without_ephemeral_response(request, nil, &block)
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,6 @@
1
+ module EphemeralResponse
2
+ class NullOutput
3
+ def puts(*args)
4
+ end
5
+ end
6
+ end
@@ -3,6 +3,43 @@ require 'spec_helper'
3
3
  describe EphemeralResponse::Configuration do
4
4
  subject { EphemeralResponse::Configuration }
5
5
 
6
+ describe ".debug_output=" do
7
+ it "raises an exception when the argument isn't an IO object" do
8
+ expect do
9
+ subject.debug_output = :foo
10
+ end.to raise_exception(EphemeralResponse::Error, /must respond to #puts/)
11
+ end
12
+
13
+ it "stores the argument" do
14
+ subject.debug_output = $stderr
15
+ subject.instance_variable_get(:@debug_output).should == $stderr
16
+ end
17
+ end
18
+
19
+ describe ".debug_output" do
20
+ it "defaults to being off (NullOutput)" do
21
+ subject.debug_output.should be_instance_of(EphemeralResponse::NullOutput)
22
+ end
23
+
24
+ it "returns the the result of the setter" do
25
+ subject.debug_output = $stdout
26
+ subject.debug_output.should == $stdout
27
+ end
28
+ end
29
+
30
+ describe "#fixture_set" do
31
+ let(:name) { 'name' }
32
+
33
+ subject { EphemeralResponse::Configuration.fixture_set }
34
+
35
+ it { should be_nil }
36
+
37
+ it "can be overwritten" do
38
+ EphemeralResponse::Configuration.fixture_set = name
39
+ should == name
40
+ end
41
+ end
42
+
6
43
  describe "#fixture_directory" do
7
44
  it "has a default" do
8
45
  subject.fixture_directory.should == "spec/fixtures/ephemeral_response"
@@ -14,6 +51,33 @@ describe EphemeralResponse::Configuration do
14
51
  end
15
52
  end
16
53
 
54
+ describe "#effective_directory" do
55
+ it "defaults to the fixture directory" do
56
+ subject.effective_directory.should == "spec/fixtures/ephemeral_response"
57
+ end
58
+
59
+ context "with a fixture_set" do
60
+ before do
61
+ subject.fixture_directory = "test/fixtures/ephemeral_response"
62
+ subject.fixture_set = :setname
63
+ end
64
+
65
+ it "adds the fixture_set to the fixture directory" do
66
+ subject.effective_directory.should == "test/fixtures/ephemeral_response/setname"
67
+ end
68
+
69
+ context "that has been reset to the default" do
70
+ before do
71
+ subject.fixture_set = :default
72
+ end
73
+
74
+ it "resets to the fixture directory" do
75
+ subject.effective_directory.should == "test/fixtures/ephemeral_response"
76
+ end
77
+ end
78
+ end
79
+ end
80
+
17
81
  describe "#expiration" do
18
82
  it "defaults to 86400" do
19
83
  subject.expiration.should == 86400
@@ -82,6 +146,12 @@ describe EphemeralResponse::Configuration do
82
146
  subject.reset
83
147
  subject.host_registry.should be_empty
84
148
  end
149
+
150
+ it "resets debug_output" do
151
+ subject.debug_output = $stderr
152
+ subject.reset
153
+ subject.debug_output.should be_instance_of(EphemeralResponse::NullOutput)
154
+ end
85
155
  end
86
156
 
87
157
  describe "#white_list" do
@@ -23,7 +23,7 @@ describe EphemeralResponse::Fixture do
23
23
  EphemeralResponse::Fixture.load_all
24
24
  end
25
25
 
26
- context "fixture files exist" do
26
+ context "default set fixture files exist" do
27
27
  before do
28
28
  FileUtils.mkdir_p fixture_directory
29
29
  Dir.chdir(fixture_directory) do
@@ -37,6 +37,24 @@ describe EphemeralResponse::Fixture do
37
37
  EphemeralResponse::Fixture.load_all
38
38
  end
39
39
  end
40
+
41
+ context "fixture files exist for the set" do
42
+ let(:dir) { "#{fixture_directory}/name" }
43
+
44
+ before do
45
+ EphemeralResponse.fixture_set = :name
46
+ FileUtils.mkdir_p dir
47
+ Dir.chdir(dir) do
48
+ FileUtils.touch %w(1.yml 2.yml)
49
+ end
50
+ end
51
+
52
+ it "calls #load_fixture for each fixture file" do
53
+ EphemeralResponse::Fixture.should_receive(:load_fixture).with("#{dir}/1.yml")
54
+ EphemeralResponse::Fixture.should_receive(:load_fixture).with("#{dir}/2.yml")
55
+ EphemeralResponse::Fixture.load_all
56
+ end
57
+ end
40
58
  end
41
59
 
42
60
  describe ".load_fixture" do
@@ -45,6 +63,11 @@ describe EphemeralResponse::Fixture do
45
63
  EphemeralResponse::Fixture.load_fixture(fixture.path)
46
64
  EphemeralResponse::Fixture.fixtures.should have_key(fixture.identifier)
47
65
  end
66
+
67
+ it "handles empty yaml files" do
68
+ FileUtils.touch '3.yml'
69
+ EphemeralResponse::Fixture.load_fixture('3.yml').should be_nil
70
+ end
48
71
  end
49
72
 
50
73
  describe ".register" do
@@ -298,6 +321,11 @@ describe EphemeralResponse::Fixture do
298
321
  fixture.register
299
322
  EphemeralResponse::Fixture.fixtures.should have_key(fixture.identifier)
300
323
  end
324
+
325
+ it "debugs saving the fixture" do
326
+ EphemeralResponse::Configuration.debug_output.should_receive(:puts).with("GET http://example.com/ saved as #{fixture.path}")
327
+ fixture.register
328
+ end
301
329
  end
302
330
 
303
331
  context "uri is white listed" do
@@ -18,8 +18,12 @@ describe "Read Body Compatibility" do
18
18
  Net::HTTP::Get.new '/'
19
19
  end
20
20
 
21
- def send_request(req, data=nil)
22
- http.start {|h| h.request(req, data) }
21
+ def new_post
22
+ Net::HTTP::Post.new('/')
23
+ end
24
+
25
+ def send_request(req, body=nil)
26
+ http.start {|h| h.request(req, body) }
23
27
  end
24
28
 
25
29
  context "open-uri" do
@@ -45,12 +49,16 @@ describe "Read Body Compatibility" do
45
49
 
46
50
  context "Net::HTTP.post" do
47
51
  it "generates a fixture, then uses the fixture" do
48
- post = Net::HTTP::Post.new('/')
52
+ post = new_post
53
+ post.body = 'foo=bar'
54
+
49
55
  real_response = nil
50
56
  http.post('/', 'foo=bar') {|s| real_response = s}
57
+
51
58
  fixture = EphemeralResponse::Fixture.find(uri, post)
52
59
  File.exists?(fixture.path).should be_true
53
- fixture_response = send_request(post, 'foo=bar').body
60
+
61
+ fixture_response = send_request(new_post, 'foo=bar').body
54
62
  real_response.should == fixture_response
55
63
  end
56
64
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Sets" do
4
+ let(:uri) { URI.parse('http://localhost:9876/') }
5
+ let(:http) { Net::HTTP.new uri.host, uri.port }
6
+ let(:get) { Net::HTTP::Get.new '/' }
7
+
8
+ before do
9
+ clear_fixtures
10
+ end
11
+
12
+ context "default set" do
13
+ it "saves one fixture to the default directory" do
14
+ EphemeralResponse::RackReflector.while_running do
15
+ http.start {|h| h.request(get) }
16
+ EphemeralResponse::Fixture.fixtures.should_not be_empty
17
+ Dir.glob("#{EphemeralResponse::Configuration.fixture_directory}/*").size.should == 1
18
+ end
19
+ end
20
+
21
+ it "restores the fixture" do
22
+ clear_fixtures
23
+ body = nil
24
+ EphemeralResponse::RackReflector.while_running do
25
+ body = http.start {|h| h.request(get) }
26
+ end
27
+ http.start {|h| h.request(get) }.should == body
28
+ end
29
+ end
30
+
31
+ context "named set" do
32
+ let(:name) { 'name' }
33
+
34
+ describe "#fixture_set=" do
35
+ it "unloads the existing fixtures" do
36
+ EphemeralResponse::RackReflector.while_running do
37
+ http.start {|h| h.request(get) }
38
+ EphemeralResponse.fixture_set = name
39
+ EphemeralResponse::Fixture.fixtures.should be_empty
40
+ end
41
+ end
42
+
43
+ it "reloads any existing fixtures for the set" do
44
+ EphemeralResponse::RackReflector.while_running do
45
+ EphemeralResponse.fixture_set = name
46
+ http.start {|h| h.request(get) }
47
+ end
48
+ EphemeralResponse.fixture_set = :default
49
+ EphemeralResponse.fixture_set = name
50
+ EphemeralResponse::Fixture.find(uri, get).should be
51
+ end
52
+ end
53
+
54
+ it "saves one fixture to the set directory only" do
55
+ EphemeralResponse::RackReflector.while_running do
56
+ EphemeralResponse.fixture_set = name
57
+ http.start {|h| h.request(get) }
58
+ EphemeralResponse::Fixture.fixtures.should_not be_empty
59
+ File.exists?("#{EphemeralResponse::Configuration.fixture_directory}/#{name}").should be_true
60
+ Dir.glob("#{EphemeralResponse::Configuration.fixture_directory}/#{name}/*").size.should == 1
61
+ end
62
+ end
63
+
64
+ it "reads the fixture back from the set directory" do
65
+ body = nil
66
+ EphemeralResponse::RackReflector.while_running do
67
+ EphemeralResponse.fixture_set = name
68
+ body = http.start {|h| h.request(get) }
69
+ EphemeralResponse::Fixture.fixtures.should_not be_empty
70
+ end
71
+ http.start {|h| h.request(get) }.should == body
72
+ end
73
+ end
74
+ end
@@ -11,6 +11,7 @@ module UniqueRequests
11
11
  post_with_body
12
12
  post_with_data_and_query_string
13
13
  post_with_data_and_query_string_and_basic_auth
14
+ post_with_manual_request_body
14
15
  )
15
16
 
16
17
  def uri
@@ -23,15 +24,20 @@ module UniqueRequests
23
24
 
24
25
  def set_up_responses
25
26
  VARIATIONS.each do |request|
26
- responses[request] = send(request)
27
+ response = send(request)
28
+ if responses.values.include?(response)
29
+ fail "Duplicate response for #{request.inspect}"
30
+ else
31
+ responses[request] = response
32
+ end
27
33
  end
28
34
  end
29
35
 
30
- def perform(request)
36
+ def perform(request, body=nil)
31
37
  http = Net::HTTP.new uri.host, uri.port
32
38
  # http.set_debug_output $stdout
33
39
  http.start do |http|
34
- http.request(request)
40
+ http.request(request, body)
35
41
  end
36
42
  end
37
43
 
@@ -68,26 +74,30 @@ module UniqueRequests
68
74
 
69
75
  def post_with_body
70
76
  request = Net::HTTP::Post.new('/')
71
- request.body = 'hi=there'
77
+ request.body = 'post_with=body'
72
78
  perform request
73
79
  end
74
80
 
75
81
  def post_with_data_and_query_string
76
82
  request = Net::HTTP::Post.new('/?foo=bar')
77
- request.set_form_data 'hi' => 'there'
83
+ request.set_form_data 'post_with' => 'data_and_query_string'
78
84
  perform request
79
85
  end
80
86
 
81
87
  def post_with_data_and_query_string_and_basic_auth
82
88
  request = Net::HTTP::Post.new('/?foo=bar')
83
89
  request.basic_auth 'user', 'password'
84
- request.set_form_data 'hi' => 'there'
90
+ request.set_form_data 'post_with' => 'data_and_query_string_and_basic_auth'
85
91
  perform request
86
92
  end
87
93
 
94
+ def post_with_manual_request_body
95
+ perform Net::HTTP::Post.new('/'), 'post_with=manual_request_body'
96
+ end
97
+
88
98
  end
89
99
 
90
- describe "Unique fixtures generated for the following requests" do
100
+ describe "Repeated requests properly reloaded" do
91
101
  include UniqueRequests
92
102
 
93
103
  before :all do
@@ -98,10 +108,6 @@ describe "Unique fixtures generated for the following requests" do
98
108
  end
99
109
  end
100
110
 
101
- after :all do
102
- EphemeralResponse::RackReflector.stop
103
- end
104
-
105
111
  UniqueRequests::VARIATIONS.each do |request|
106
112
  it "restores the correct response from the fixture" do
107
113
  send(request).body.should == responses[request].body
@@ -150,4 +156,14 @@ describe "Unique fixtures generated for the following requests" do
150
156
  http.request(get).body.should == EphemeralResponse::Fixture.find(http.uri, get).response.body
151
157
  end
152
158
  end
159
+
160
+ context "when changing the fixture set" do
161
+ it "attempts to access the server which is not available" do
162
+ EphemeralResponse.fixture_set = :server_down
163
+ expect do
164
+ simple_get
165
+ end.to raise_exception(Errno::ECONNREFUSED, /connection refused/i)
166
+ EphemeralResponse.fixture_set = :default
167
+ end
168
+ end
153
169
  end
@@ -9,15 +9,21 @@ Dir.glob("spec/support/*.rb") {|f| require File.expand_path(f, '.')}
9
9
 
10
10
  Spec::Runner.configure do |config|
11
11
  config.include ClearFixtures
12
+
12
13
  config.before(:suite) do
13
14
  ClearFixtures.clear_fixtures
14
15
  end
15
- config.before(:each) do
16
- EphemeralResponse::Configuration.reset
17
- EphemeralResponse.activate
18
- end
16
+
19
17
  config.after(:suite) do
20
18
  EphemeralResponse.deactivate
21
19
  ClearFixtures.clear_fixtures
22
20
  end
21
+
22
+ config.before(:each) do
23
+ EphemeralResponse.activate
24
+ end
25
+
26
+ config.after(:each) do
27
+ EphemeralResponse::Configuration.reset
28
+ end
23
29
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ephemeral_response
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 3
8
- - 2
9
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Sandro Turriate
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-07-30 00:00:00 -04:00
19
+ date: 2011-01-18 00:00:00 -05:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -26,6 +27,7 @@ dependencies:
26
27
  requirements:
27
28
  - - ">="
28
29
  - !ruby/object:Gem::Version
30
+ hash: 7
29
31
  segments:
30
32
  - 1
31
33
  - 4
@@ -41,6 +43,7 @@ dependencies:
41
43
  requirements:
42
44
  - - ">="
43
45
  - !ruby/object:Gem::Version
46
+ hash: 13
44
47
  segments:
45
48
  - 1
46
49
  - 2
@@ -56,6 +59,7 @@ dependencies:
56
59
  requirements:
57
60
  - - ">="
58
61
  - !ruby/object:Gem::Version
62
+ hash: 11
59
63
  segments:
60
64
  - 0
61
65
  - 5
@@ -71,6 +75,7 @@ dependencies:
71
75
  requirements:
72
76
  - - ">="
73
77
  - !ruby/object:Gem::Version
78
+ hash: 21
74
79
  segments:
75
80
  - 0
76
81
  - 2
@@ -86,6 +91,7 @@ dependencies:
86
91
  requirements:
87
92
  - - ">="
88
93
  - !ruby/object:Gem::Version
94
+ hash: 23
89
95
  segments:
90
96
  - 1
91
97
  - 0
@@ -104,6 +110,7 @@ extra_rdoc_files:
104
110
  files:
105
111
  - .document
106
112
  - .gitignore
113
+ - .rvmrc
107
114
  - Gemfile
108
115
  - History.markdown
109
116
  - MIT_LICENSE
@@ -119,6 +126,7 @@ files:
119
126
  - lib/ephemeral_response/configuration.rb
120
127
  - lib/ephemeral_response/fixture.rb
121
128
  - lib/ephemeral_response/net_http.rb
129
+ - lib/ephemeral_response/null_output.rb
122
130
  - lib/ephemeral_response/request.rb
123
131
  - spec/ephemeral_response/configuration_spec.rb
124
132
  - spec/ephemeral_response/fixture_spec.rb
@@ -127,6 +135,7 @@ files:
127
135
  - spec/integration/custom_identifier_spec.rb
128
136
  - spec/integration/normal_flow_spec.rb
129
137
  - spec/integration/read_body_compatibility_spec.rb
138
+ - spec/integration/sets_spec.rb
130
139
  - spec/integration/unique_fixtures_spec.rb
131
140
  - spec/integration/white_list_spec.rb
132
141
  - spec/spec.opts
@@ -149,6 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
158
  requirements:
150
159
  - - ">="
151
160
  - !ruby/object:Gem::Version
161
+ hash: 3
152
162
  segments:
153
163
  - 0
154
164
  version: "0"
@@ -157,6 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
167
  requirements:
158
168
  - - ">="
159
169
  - !ruby/object:Gem::Version
170
+ hash: 3
160
171
  segments:
161
172
  - 0
162
173
  version: "0"
@@ -175,6 +186,7 @@ test_files:
175
186
  - spec/integration/custom_identifier_spec.rb
176
187
  - spec/integration/normal_flow_spec.rb
177
188
  - spec/integration/read_body_compatibility_spec.rb
189
+ - spec/integration/sets_spec.rb
178
190
  - spec/integration/unique_fixtures_spec.rb
179
191
  - spec/integration/white_list_spec.rb
180
192
  - spec/spec_helper.rb