Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking with rspec and mocha together

For a test suite that's already using mocha for mocking, can new tests be written with rspec mocking? maybe turn that on before(:all) and turn it back to mocha after(:all)

I tried changing the Spec::Runner configuration at run-time and that didn't seem to work with mocking

like image 848
Samer Buna Avatar asked Oct 14 '22 22:10

Samer Buna


2 Answers

I have published a new gem for this. You can find more details here -> http://github.com/endeepak/rspec-multi-mock

like image 194
Deepak N Avatar answered Oct 23 '22 07:10

Deepak N


It sounds like Deepak's RSpec Multi Mock gem solves this.

But you should ask yourself if this is really what you want. Ultimately, consistency is most important, and using a mix of mocking frameworks within the same app is bound to lead to confusion.

Personally I'm quite happy with RSpec's built-in mocking and don't usually find the need for Mocha on my own projects. But some of my peers prefer Mocha and I'm not really aware of any limitations of Mocha compared to vanilla RSpec mocking, so I'd recommend sticking with Mocha if that's what the app already uses. Even though I know its "any_instance" support is considered a code smell by some, it does occasionally come in very handy. :)

like image 1
Mirko Froehlich Avatar answered Oct 23 '22 09:10

Mirko Froehlich