question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

specHelper should allow response metadata to be turned off

See original GitHub issue

When using specHelper, test server rules for response metadata are not respected

  • ActionHero Version: 15.1.0
  • Node.js Version: 4.5.0
  • Operating System OSX

Issue description

When running a unit tests with specHelper, it would be helpful if we could turn off response metadata, because it can interfere with testing the expected responses. An example of how this affects testing is as follows:

I have an action that returns a json array as a response, if I cannot turn off my metadata, the array I get back looks like: [ { id: 'f05f9d0a-6587-4672-8467-d02f7e525e63', name: 'My Box', path: 'app/my-box', category_id: 'f7ff85a0-faaa-11e5-a8a9-7fa3b294cd46' }, { id: '498efd35-f17a-47e6-a365-f5a3a075911e', name: 'My Box Other', path: 'app/my-box-other', category_id: 'f7ff85a0-faaa-11e5-a8a9-7fa3b294cd46' }, messageCount: 1, serverInformation: { serverName: 'cerberus-mock-api', apiVersion: '0.0.1' }, requesterInformation: { id: 'b263bbc5-9d4b-4cd8-8c96-e125d448baf3', remoteIP: 'testServer', receivedParams: { action: 'getSafeDepositBoxList', apiVersion: 1 } } ]

This means that in order to get the actual response, I have to do something like: var trueResponse = [response[0], response[1]];

Which is not ideal. And it gets even worse for when I want to test for an empty array as a response.

In all cases where I run an actual server, these are properties I can turn off, but digging into the specHelper code, there is no way to turn this off for this mock server functionality. Ideally it should either have its own config setting that it decides on, or it should respect the test settings, or it should be able to take an options argument.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
evantahlercommented, Nov 4, 2016

And now, the actual solve to the question you initially asked: https://github.com/evantahler/actionhero/pull/980

api.specHelper.returnMetadata = false

1reaction
evantahlercommented, Nov 4, 2016

The first thing that this issue points out is that we are aren’t being “type safe” (as safe as you can be in JS) with regard to our error handling and metadata in the SpecHelper.

We shouldn’t do things like data.response.error = error if typeof data.response === 'string'!

This should help that https://github.com/evantahler/actionhero/pull/979

Read more comments on GitHub >

github_iconTop Results From Across the Web

RSpec 3.5 has been released!
Spec files that need it can then require the support file and tag ... One of the common uses for RSpec's metadata system...
Read more >
rspec - "Cookbook apache_wrapper not found" when running ...
You must specify "apache2" as dependency in your cookbooks metadata.rb : name 'COOKBOOK NAME' maintainer 'YOUR NAME' maintainer_email ...
Read more >
Rails Testing guidelines | Mashup Garage Playbook
There's no need to test if ActiveRecord validations work for example, when ActiveRecord itself already has tests for those. TDD is not required, ......
Read more >
Testing with HTTP Requests | Cloudbees Blog
The second reason you need to wrap your APIs is that it can make ... Webmock allows us to provide fake HTTP responses,...
Read more >
spec/spec_helper.rb · master - GitLab.org
warn 'make sure spec_helper is loaded first, or run rspec with `-r spec_helper`.' 7. abort 'Aborting...' 8. end. 9. 10. # Enable deprecation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found