Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using allow_any_instance_of in a scenario #8

Open
Jimmy89 opened this issue Oct 12, 2018 · 1 comment
Open

Using allow_any_instance_of in a scenario #8

Jimmy89 opened this issue Oct 12, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@Jimmy89
Copy link

Jimmy89 commented Oct 12, 2018

Hello,

From what I understood of the original project, rspec mocking commands should be supported. I have tried to use allow_any_instance_of(Class).to receive(:check).and_return([]) as the only command in the basic scenario file (of the provided examples). However, my Rails returns an error when I try to execute this. Do you have any clue how I can get this to work?

Text from the original project:

In the scenario you also have access to RSpec mocking functions. So you could do something like:

scenario :basic do
  allow(ExternalService).to receive(:retrieve).and_return("result")
end

Thanks a lot!

Update:
By adding the following code, I managed to get it to work! However, I am curious if there's a better way. Also, is there a way to clean up my spec changes for when I don't want to mock anymore? Any idea's?

require 'rspec/rails'
RSpec::Mocks.teardown
RSpec::Mocks.setup
extend RSpec::Mocks::ExampleMethods
allow_any_instance_of(Class).to receive(:check).and_return([])
@grantspeelman
Copy link
Owner

grantspeelman commented Oct 14, 2018

yes, the original it was part of the project but in order to make it more flexible, I removed more of the built-in functionality in favour of more simple ruby files that are simply called which allows you to do more customisations.
The ruby files that are generated are really only examples, so feel free to modify/add/delete to fit your need.

A word of caution, whatever you require/modify will stay in the running process and could have unexpected side effects. ie RSpec was not built with the idea of it renaming in a running process

That said, I'll look into using your code to add another example file to the cypress-on-rails generator

@grantspeelman grantspeelman added the enhancement New feature or request label Oct 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants