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
0 answers

Rails: Mocha gem how to test exception

Below is my code begin Test.testcode rescue end i want to test my exception handling logic and for that i am doing Test.stubs(:testcode).raises(Exception,"jkkh") but my test is not passing. i am getting below error in test cases
user2274074
  • 991
  • 2
  • 9
  • 25
0
votes
3 answers

How do I expect a method to be run with specific ActiveRecord parameters

Using Mocha on Rails 4.2. I'm testing a method that it should make a call to another method with the correct parameters. These parameters are ActiveRecord objects that it calls up from the database. Here is the key line in my…
Toby 1 Kenobi
  • 4,717
  • 2
  • 29
  • 43
0
votes
2 answers

Test method that was called from other method

I have module Database with method generate_from_database that spins for loops and calls method get_length. How can I test if get_length was called n times, by using rspec or mocha? module Database class Length < ActiveRecord::Base def…
Mario
  • 335
  • 7
  • 20
0
votes
1 answer

How mocking works mocha gem?

I am new to mocha gem before that I am using minitest to test my product. Then I came across a situation where my application is publishing jobs to facebook. It selects some jobs and then publish them on facebook. So somebody told me to use mocking…
Zia Qamar
  • 1,694
  • 1
  • 15
  • 35
0
votes
0 answers

Does the Rails after_filter get executed before or after Mocha's automatic call to unstub?

My controller class inherits from ActionController::Base. I am using rails 2 and ruby 1.9.3. I am using Mocha to stub out calls to Perforce so my tests are not dependent on connections to perforce. In my rails after_filter, I call one of my stubbed…
Paul Chernoch
  • 5,275
  • 3
  • 52
  • 73
0
votes
1 answer

Stub specific instances of a class in a functional test

I want to test that a specific icon gets displayed in the view for a User with a streak more than X no of days. So I need to stub a streak method of the User model.But I want that it stubs the method only for a specific user based on its uid. The…
ananyo2012
  • 63
  • 9
0
votes
1 answer

Why am I getting a NoMethodError when I use Mocha 0.9.8 with Test::Unit 2.1.1

Has anyone seen this? Here's the error: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -rrubygems -e "require 'redgreen'" -I.:lib:test -rubygems -e "['test/unit', 'test/test_authentication.rb'].each { |f| require f }" |…
AndrewVos
  • 1,297
  • 2
  • 14
  • 25
0
votes
1 answer

Mock Time.now with mocha

To mock Time.now with the mocha gem I use the following oneliner. require 'minitest/autorun' require 'mocha/mini_test' require 'time' …
sschmeck
  • 7,233
  • 4
  • 40
  • 67
0
votes
1 answer

How does Ruby Mocha stub a nested hash?

I have a method here that needs to be mocked using Mocha, but currently i have no clue how to mock the nested hash here. Products.new(:A => "aa", :B => "bb").containers['container_A'].elements['element_b'] So far, i know how to stub Products.new(:A…
Cloud_cal
  • 132
  • 2
  • 12
0
votes
1 answer

RSpec, Mocha and Rubymine - Undefined method `mocha_setup'

I have two styles of spec in a single folder, one of which uses a full-fat rails environment, with rspec, the other is a light-weight helper which requires gems individually. Recently I've had some problems running these together in Rubymine.…
AJFaraday
  • 2,411
  • 1
  • 16
  • 39
0
votes
1 answer

mocha gem stub method and assign response

In this example I use rr gem, and stub an object method which is obj.project here, and assign returned value to any variable(in this case that is project_data ) when the method is called from any other method or class. obj = Object.new …
Johnny Cash
  • 4,867
  • 5
  • 21
  • 37
0
votes
1 answer

rr gem assert_received equivalent in mocha gem

Now I use rr gem to stub Project model count method, and then I replicate index action to check the count method is called or not. I'm planning to use mocha gem but I don't figure out what is the equivalent of assert_received method in mocha gem.…
Johnny Cash
  • 4,867
  • 5
  • 21
  • 37
0
votes
2 answers

Weird error when trying to test method with argument in Mocha. Is it a bug or is it me?

It's rather hard to find any documentation on Mocha, so I'm afraid I'm totally at sea here. I have found a problem with stubbing methods that pass arguments. So for instance if I set up a class like this: class Red def gets(*args) …
i0n
  • 916
  • 1
  • 8
  • 26
0
votes
1 answer

Konacha, Mocha, BackboneJS and Ruby on Rails configuration

I am using Konacha to test a BackboneJS application in my Ruby on Rails application. I have read about every tutorial on the web and it shows how easy it is to set up and get working. Unfortunately, I am not having this level of success. Here is…
Mike Riley
  • 282
  • 3
  • 20
0
votes
2 answers

Testing methods called on yielded object

I have the following controller test case: def test_showplain Cleaner.expect(:parse).with(@somecontent) Cleaner.any_instance.stubs(:plainversion).returns(@returnvalue) post :showplain, {:content => @somecontent} end This works fine, except…
Todd R
  • 18,236
  • 8
  • 31
  • 39