Questions tagged [ruby-mocha]

Mocha is a Ruby library for mocking and unit testing. For the JS library use [mocha.js]. Use with [ruby] or [ruby-on-rails]

114 questions
0
votes
1 answer

What is the scope of the mocks created by mocha when used in rspec?

In my rspec test suite I use mocha library to create mocks/stubs and test doubles. Examples in my rspec suite run in random order, as recommended. For some reason a few examples now fail randomly. I already ruled out shared database state and global…
Alex Kovshovik
  • 4,085
  • 4
  • 35
  • 36
0
votes
1 answer

How to mock associated objects in Rails?

I know that I can mock objects as follows: Account.any_instance.expects(:type).returns("premium") I remember hearing that this is considered a poor practice. I'd love to do something like user =…
sakovias
  • 1,356
  • 1
  • 17
  • 26
0
votes
1 answer

Ruby Mocha Unittest can't find "has_key" method

I've written a Unit test using Test::Unit and Mocha. I'm using "expects" to mock a method in a class I'm testing, and I want to check if a certain parameter is passed into the object: service.expects(:get).once.with(path,…
PrimaryFeather
  • 479
  • 3
  • 12
0
votes
1 answer

How do I subclass mocks in Mocha?

I need to mock an object whose class is expected to have a few constants defined, e.g: class Driver DRIVER_NAME = "google" end I don't want to simply use instances of the class in my unit tests because of expensive initialization, plus it has a…
Hubro
  • 56,214
  • 69
  • 228
  • 381
0
votes
1 answer

Difference between RR mock.instance_of and Mocha any_instance

I have the following rspec code: require 'spec_helper' require 'mocha' require 'rr' describe ProjectsController, "creating a new project" do integrate_views it "should redirect to project with a notice on successful save" do …
Jason
  • 1
  • 2
0
votes
1 answer

Mocha for same method needs to return 2 different values

Using Mocha, I'm stubbing the same method that needs to return 2 separate values. No matter what I do, it only returns 1 of the 2 values, thus 1 of my rspec tests always fail. How do I get the stub to return the correct value at the right…
David Nix
  • 3,324
  • 3
  • 32
  • 51
0
votes
1 answer

Why is mocha not stubbing this method in my Rails 3 integration test?

I have the following: setup do Capybara.current_driver = Capybara.javascript_driver @project.user = @user @project.save Project.any_instance.stubs(:price_all) end And yet I have a test failing because the Project.price_all…
croceldon
  • 4,511
  • 11
  • 57
  • 92
0
votes
1 answer

NoMethodError: undefined method `mock' for minitest and mocha

I'm developing a gem for Rails 3 and came across an error in my test suit when running it under Ruby 1.8.7 at travis-ci.org: /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:874:in `_run_suite': undefined method `run'…
Piotrek Okoński
  • 600
  • 8
  • 17
-1
votes
1 answer

How to stub a method called in configuration block in sinatra application?

As per sinatra documentation, we use configure block to run something once at startup. http://sinatrarb.com/intro.html Consider, the below configure where I am fetching the credentials using Creds class and setting to creds. configure do #…
Raunak Kapoor
  • 731
  • 6
  • 14
1 2 3 4 5 6 7
8