mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Avoid redefining classes between tests.
Defining classes within tests pollutes other namespaces, causing warnings that classes are being redefined when running tests. This change creates anonymous classes for use within individual tests.
This commit is contained in:
parent
60179afb4a
commit
2291d553a6
3 changed files with 10 additions and 9 deletions
|
@ -27,10 +27,10 @@ RSpec.describe HTTParty::Parser do
|
|||
end
|
||||
|
||||
it "returns the SupportedFormats constant for subclasses" do
|
||||
class MyParser < HTTParty::Parser
|
||||
SupportedFormats = {"application/atom+xml" => :atom}
|
||||
end
|
||||
expect(MyParser.formats).to eq({"application/atom+xml" => :atom})
|
||||
klass = Class.new(HTTParty::Parser)
|
||||
klass::SupportedFormats = { "application/atom+xml" => :atom }
|
||||
|
||||
expect(klass.formats).to eq({"application/atom+xml" => :atom})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -591,7 +591,7 @@ RSpec.describe HTTParty::Request do
|
|||
stub_request(:get, 'http://api.foo.com/v2')
|
||||
.to_return(body: '<hash><foo>bar</foo></hash>')
|
||||
body = ""
|
||||
response = @request.perform { |chunk| body += chunk }
|
||||
@request.perform { |chunk| body += chunk }
|
||||
expect(body.length).to eq(27)
|
||||
end
|
||||
|
||||
|
|
|
@ -358,11 +358,12 @@ RSpec.describe HTTParty do
|
|||
|
||||
it "raises UnsupportedFormat when the parser cannot handle the format" do
|
||||
@klass.format :json
|
||||
class MyParser < HTTParty::Parser
|
||||
SupportedFormats = {}
|
||||
end unless defined?(MyParser)
|
||||
|
||||
parser_class = Class.new(HTTParty::Parser)
|
||||
parser_class::SupportedFormats = {}
|
||||
|
||||
expect do
|
||||
@klass.parser MyParser
|
||||
@klass.parser parser_class
|
||||
end.to raise_error(HTTParty::UnsupportedFormat)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue