How to ignore the request body match for an specific host in rspec VCR?How to rollback a specific migration?How to check if a specific key is present in a hash or not?How to run a single RSpec test?Unable to record Whois requests with VCR?VCR ignored parameter: Get real http requestHow to install a specific version of a ruby gem?Rspec + savon + vcr not recordingusing VCR with Rspec in feature scenariosCan I log the unhandled VCR request body?Testing a Thor script with rspec and vcr

How to understand flavors and when to use combination of them?

Tesco's Burger Relish Best Before End date number

How many Jimmys can fit?

Category-theoretic treatment of diffs, patches and merging?

SQL Server Sch-S locks on unrelated tables

Is this car delivery via Ebay Motors on Craigslist a scam?

Curly braces adjustment in tikz?

How do I use my adapted PS2 keyboard & mouse on a windows 10 computer?

What was the significance of Spider-Man: Far From Home being an MCU Phase 3 film instead of a Phase 4 film?

How do I explain that I don't want to maintain old projects?

How did the IEC decide to create kibibytes?

I'm feeling like my character doesn't fit the campaign

QR codes, do people use them?

Is there a formal/better word than "skyrocket" for the given context?

Array or vector? Two dimensional array or matrix?

Forward DNS request to my work's jump server

Is space division multiplexing really multiplexing?

What are the consequences for a developed nation to not accept any refugees?

Four ships at the ocean with the same distance

What is the average number of draws it takes before you can not draw any more cards from the Deck of Many Things?

How was the website able to tell my credit card was wrong before it processed it?

How should I ask for a "pint" in countries that use metric?

Chilling water in copper vessel

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant



How to ignore the request body match for an specific host in rspec VCR?


How to rollback a specific migration?How to check if a specific key is present in a hash or not?How to run a single RSpec test?Unable to record Whois requests with VCR?VCR ignored parameter: Get real http requestHow to install a specific version of a ruby gem?Rspec + savon + vcr not recordingusing VCR with Rspec in feature scenariosCan I log the unhandled VCR request body?Testing a Thor script with rspec and vcr






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have ElasticSearch and Kibana integration with my rails application, and i use they for log and measure requests to external API's. I don't want that VCR match the body for ElasticSearch requests records, because there are a "current time" (created_at) field in every log, that breaks VCR older records.



This is my current configuration



VCR.configure do |c|
c.ignore_localhost = true
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'

vcr_mode = ENV['VCR_MODE'] =~ /rec/i ? :all : :once

c.hook_into :webmock
c.default_cassette_options[:record] = vcr_mode
c.configure_rspec_metadata!
end


This is the log method in my custom REST client.



 def log(method, params, response, comments:)
Rails.logger.info(response.inspect)

Elastic::LogServices
.log_request(comments,
method: method,
source: ENV['HOSTNAME'],
url: response.env.url.to_s,
header: response.env.request_headers,
body: params,
type: :out,
response_header: response.headers,
response_body: response.body,
response_status: response.status)
end


In the log services...



 def self.log_request(comments = '',
created_at: nil,
method:,
source:,
url:,
header:,
body:,
type:,
response_header:,
response_body: '?',
response_status:,
format: 'REST')
log =
Elastic::Request::Log
.new(created_at: created_at,
method: method,
source: source,
url: url,
header: header,
body: JSON.pretty_generate(body),
type: type,
response:

header: response_header,
body: JSON.pretty_generate(response_body),
status: response_status
,
format: format,
comments: comments)

Elastic::Request::LogJob.perform_async(log)
end


This field is in the log entity class



 @created_at = created_at || Time.now.utc.iso8601


Also, i dont want to Mock the "Time.now.utc.iso8601" method, because there are a lot of tests that i have to change. The application do a lot of requests to others APIs.



Anyway to configure VCR to ignore the body match for all "elasticsearch:9200" requests?










share|improve this question

















  • 1





    You can use timecop gem to freeze time at certain point

    – Martin Zinovsky
    Mar 25 at 22:05











  • Or you can write custom matcher to ignore created_at field in response body. Check out this article

    – Martin Zinovsky
    Mar 25 at 22:11











  • Or you can match on other attributes to ignore body matching since its changing every time. Check out request-matching docs. As you can see you have lots of options to choose from

    – Martin Zinovsky
    Mar 25 at 22:16












  • I solved the problem mocking the "save" method of all my "ElasticRepository" instances in test environment with "before(:all)". Thanks for the answer.

    – Henrique Fernandez Teixeira
    Mar 27 at 12:39

















2















I have ElasticSearch and Kibana integration with my rails application, and i use they for log and measure requests to external API's. I don't want that VCR match the body for ElasticSearch requests records, because there are a "current time" (created_at) field in every log, that breaks VCR older records.



This is my current configuration



VCR.configure do |c|
c.ignore_localhost = true
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'

vcr_mode = ENV['VCR_MODE'] =~ /rec/i ? :all : :once

c.hook_into :webmock
c.default_cassette_options[:record] = vcr_mode
c.configure_rspec_metadata!
end


This is the log method in my custom REST client.



 def log(method, params, response, comments:)
Rails.logger.info(response.inspect)

Elastic::LogServices
.log_request(comments,
method: method,
source: ENV['HOSTNAME'],
url: response.env.url.to_s,
header: response.env.request_headers,
body: params,
type: :out,
response_header: response.headers,
response_body: response.body,
response_status: response.status)
end


In the log services...



 def self.log_request(comments = '',
created_at: nil,
method:,
source:,
url:,
header:,
body:,
type:,
response_header:,
response_body: '?',
response_status:,
format: 'REST')
log =
Elastic::Request::Log
.new(created_at: created_at,
method: method,
source: source,
url: url,
header: header,
body: JSON.pretty_generate(body),
type: type,
response:

header: response_header,
body: JSON.pretty_generate(response_body),
status: response_status
,
format: format,
comments: comments)

Elastic::Request::LogJob.perform_async(log)
end


This field is in the log entity class



 @created_at = created_at || Time.now.utc.iso8601


Also, i dont want to Mock the "Time.now.utc.iso8601" method, because there are a lot of tests that i have to change. The application do a lot of requests to others APIs.



Anyway to configure VCR to ignore the body match for all "elasticsearch:9200" requests?










share|improve this question

















  • 1





    You can use timecop gem to freeze time at certain point

    – Martin Zinovsky
    Mar 25 at 22:05











  • Or you can write custom matcher to ignore created_at field in response body. Check out this article

    – Martin Zinovsky
    Mar 25 at 22:11











  • Or you can match on other attributes to ignore body matching since its changing every time. Check out request-matching docs. As you can see you have lots of options to choose from

    – Martin Zinovsky
    Mar 25 at 22:16












  • I solved the problem mocking the "save" method of all my "ElasticRepository" instances in test environment with "before(:all)". Thanks for the answer.

    – Henrique Fernandez Teixeira
    Mar 27 at 12:39













2












2








2








I have ElasticSearch and Kibana integration with my rails application, and i use they for log and measure requests to external API's. I don't want that VCR match the body for ElasticSearch requests records, because there are a "current time" (created_at) field in every log, that breaks VCR older records.



This is my current configuration



VCR.configure do |c|
c.ignore_localhost = true
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'

vcr_mode = ENV['VCR_MODE'] =~ /rec/i ? :all : :once

c.hook_into :webmock
c.default_cassette_options[:record] = vcr_mode
c.configure_rspec_metadata!
end


This is the log method in my custom REST client.



 def log(method, params, response, comments:)
Rails.logger.info(response.inspect)

Elastic::LogServices
.log_request(comments,
method: method,
source: ENV['HOSTNAME'],
url: response.env.url.to_s,
header: response.env.request_headers,
body: params,
type: :out,
response_header: response.headers,
response_body: response.body,
response_status: response.status)
end


In the log services...



 def self.log_request(comments = '',
created_at: nil,
method:,
source:,
url:,
header:,
body:,
type:,
response_header:,
response_body: '?',
response_status:,
format: 'REST')
log =
Elastic::Request::Log
.new(created_at: created_at,
method: method,
source: source,
url: url,
header: header,
body: JSON.pretty_generate(body),
type: type,
response:

header: response_header,
body: JSON.pretty_generate(response_body),
status: response_status
,
format: format,
comments: comments)

Elastic::Request::LogJob.perform_async(log)
end


This field is in the log entity class



 @created_at = created_at || Time.now.utc.iso8601


Also, i dont want to Mock the "Time.now.utc.iso8601" method, because there are a lot of tests that i have to change. The application do a lot of requests to others APIs.



Anyway to configure VCR to ignore the body match for all "elasticsearch:9200" requests?










share|improve this question














I have ElasticSearch and Kibana integration with my rails application, and i use they for log and measure requests to external API's. I don't want that VCR match the body for ElasticSearch requests records, because there are a "current time" (created_at) field in every log, that breaks VCR older records.



This is my current configuration



VCR.configure do |c|
c.ignore_localhost = true
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'

vcr_mode = ENV['VCR_MODE'] =~ /rec/i ? :all : :once

c.hook_into :webmock
c.default_cassette_options[:record] = vcr_mode
c.configure_rspec_metadata!
end


This is the log method in my custom REST client.



 def log(method, params, response, comments:)
Rails.logger.info(response.inspect)

Elastic::LogServices
.log_request(comments,
method: method,
source: ENV['HOSTNAME'],
url: response.env.url.to_s,
header: response.env.request_headers,
body: params,
type: :out,
response_header: response.headers,
response_body: response.body,
response_status: response.status)
end


In the log services...



 def self.log_request(comments = '',
created_at: nil,
method:,
source:,
url:,
header:,
body:,
type:,
response_header:,
response_body: '?',
response_status:,
format: 'REST')
log =
Elastic::Request::Log
.new(created_at: created_at,
method: method,
source: source,
url: url,
header: header,
body: JSON.pretty_generate(body),
type: type,
response:

header: response_header,
body: JSON.pretty_generate(response_body),
status: response_status
,
format: format,
comments: comments)

Elastic::Request::LogJob.perform_async(log)
end


This field is in the log entity class



 @created_at = created_at || Time.now.utc.iso8601


Also, i dont want to Mock the "Time.now.utc.iso8601" method, because there are a lot of tests that i have to change. The application do a lot of requests to others APIs.



Anyway to configure VCR to ignore the body match for all "elasticsearch:9200" requests?







ruby-on-rails ruby rspec rubygems vcr






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 21:44









Henrique Fernandez TeixeiraHenrique Fernandez Teixeira

114 bronze badges




114 bronze badges







  • 1





    You can use timecop gem to freeze time at certain point

    – Martin Zinovsky
    Mar 25 at 22:05











  • Or you can write custom matcher to ignore created_at field in response body. Check out this article

    – Martin Zinovsky
    Mar 25 at 22:11











  • Or you can match on other attributes to ignore body matching since its changing every time. Check out request-matching docs. As you can see you have lots of options to choose from

    – Martin Zinovsky
    Mar 25 at 22:16












  • I solved the problem mocking the "save" method of all my "ElasticRepository" instances in test environment with "before(:all)". Thanks for the answer.

    – Henrique Fernandez Teixeira
    Mar 27 at 12:39












  • 1





    You can use timecop gem to freeze time at certain point

    – Martin Zinovsky
    Mar 25 at 22:05











  • Or you can write custom matcher to ignore created_at field in response body. Check out this article

    – Martin Zinovsky
    Mar 25 at 22:11











  • Or you can match on other attributes to ignore body matching since its changing every time. Check out request-matching docs. As you can see you have lots of options to choose from

    – Martin Zinovsky
    Mar 25 at 22:16












  • I solved the problem mocking the "save" method of all my "ElasticRepository" instances in test environment with "before(:all)". Thanks for the answer.

    – Henrique Fernandez Teixeira
    Mar 27 at 12:39







1




1





You can use timecop gem to freeze time at certain point

– Martin Zinovsky
Mar 25 at 22:05





You can use timecop gem to freeze time at certain point

– Martin Zinovsky
Mar 25 at 22:05













Or you can write custom matcher to ignore created_at field in response body. Check out this article

– Martin Zinovsky
Mar 25 at 22:11





Or you can write custom matcher to ignore created_at field in response body. Check out this article

– Martin Zinovsky
Mar 25 at 22:11













Or you can match on other attributes to ignore body matching since its changing every time. Check out request-matching docs. As you can see you have lots of options to choose from

– Martin Zinovsky
Mar 25 at 22:16






Or you can match on other attributes to ignore body matching since its changing every time. Check out request-matching docs. As you can see you have lots of options to choose from

– Martin Zinovsky
Mar 25 at 22:16














I solved the problem mocking the "save" method of all my "ElasticRepository" instances in test environment with "before(:all)". Thanks for the answer.

– Henrique Fernandez Teixeira
Mar 27 at 12:39





I solved the problem mocking the "save" method of all my "ElasticRepository" instances in test environment with "before(:all)". Thanks for the answer.

– Henrique Fernandez Teixeira
Mar 27 at 12:39












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346878%2fhow-to-ignore-the-request-body-match-for-an-specific-host-in-rspec-vcr%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346878%2fhow-to-ignore-the-request-body-match-for-an-specific-host-in-rspec-vcr%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?