Questions tagged [rspec-mocks]

rspec-mocks is the part of the RSpec testing framework that provides test doubles: stubs, mocks and spies.

rspec-mocks is the part of the RSpec testing framework that provides test doubles: stubs, mocks and spies. It can be used with other test frameworks such as Cucumber (although it is only occasionally appropriate to use test doubles in Cucumber scenarios). It is implemented as a Ruby gem.

65 questions
0
votes
1 answer

Replace instance method with rspec-mock

The RSpec documentation shows how to mock a class method. How can I replace an instance method instead. Here is a code example using rspec-mocks to make this more concrete: require 'rspec' class Foo def foo "foo" end def foobar foo +…
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
0
votes
1 answer

Stubbing a module, its methods, and inner classes with RSpec

I have a module like this that I'm trying to write unit tests for module MyThing module Helpers def self.generate_archive # ... ::Configuration.export(arg) rescue ::Configuration::Error => error raise error end …
fp.monkey
  • 217
  • 1
  • 7
0
votes
1 answer

Proper way to mock ruby-core classes

I want to know whether this solution is community approved by mocking object in ruby. If not please describe why, and how can I improve design of code or maybe test. Consider I have the following code. lib/config_loader.rb class ConfigLoader …
zhisme
  • 2,368
  • 2
  • 19
  • 28
0
votes
1 answer

How do I test whether a Sidekiq worker is sending the right data to an external API?

I have a Sidekiq worker that reaches out to an external API to get some data back. I am trying to write tests to make sure that this worker is designed and functioning correctly. The worker grabs a local model instance and examines two fields on the…
Erik Jacobs
  • 841
  • 3
  • 7
  • 19
0
votes
1 answer

How to unit test a method not invoking another object method in RSpec

I have a rails controller which I would like to test a method test_method. class ActiveController < ActionController::Base def test_method user = acc_users.all_users.find params[:id] if !user.active? user.call_method! end …
thebenman
  • 1,621
  • 14
  • 35
0
votes
2 answers

How can I stub out a global function called from a constructor?

I'm trying to stub out a global function called from a constructor. I'm using Rspec and Rspec-mocks. Here's the code to be tested: def foo 'foo' end class Bar def initialize @bar = foo end def bar @bar end end And here's the…
Evan Kroske
  • 4,506
  • 12
  • 40
  • 59
0
votes
1 answer

Dependency Injection causing both Rspec failure and IRB failure

Note: I am a Ruby and programming novice. I have a class called JourneyLog I am trying to get a method called start to instantiate a new instance of another class, called Journey class JourneyLog attr_reader :journey_class def…
0
votes
1 answer

I get a deprecation warning when I use 'stub_chain' of gem 'rspec-mock'

I'm making a mock for some Object with RSpec and rspec-mocks. What I dis is the below. In Spec file describe 'foo' do before do Mock.start end end In Mock file module Mock def self.start …
0
votes
1 answer

Issue with spies in Rspec

Having trouble figuring out why: it "shifts/unshifts without O(n) copying" do arr = RingBuffer.new allow(arr.send(:store)).to receive(:[]=).and_call_original 8.times do |i| arr.unshift(i) end # Should involve 8 sets to unshift, no…
amac
  • 35
  • 5
0
votes
2 answers

Not getting the exact output when testing Create action in RSpec

I am doing my testing with mocks and stubs but I can't get the desired output I want when testing the create action in the controller. The failing test: describe 'authenticated user' do let(:user) { instance_double(User) } before do …
gogofan
  • 533
  • 1
  • 10
  • 20
0
votes
1 answer

How to stub a third party object using rspec-mock?

I'm kinda new to rspec-mock, now I'm integrating hominid to communicate with Mailchimp, I want to stub some method calls, so my request doesn't actually go to Mailchimp. Here is what I'm doing config/initilizers/mailchimp.rb MAILCHIMP =…
Hieu Pham
  • 6,577
  • 2
  • 30
  • 50
0
votes
1 answer

Rspec Mocks in Cucumber keep executing original methods

I got a cucumber step defined as follows: When(/^I click on the button to create a new target$/) do RSpec::Mocks.with_temporary_scope do dummy_connection = double('Dummy connection') allow(dummy_connection).to receive(:add_target) …
c0m3tx
  • 98
  • 1
  • 7
0
votes
2 answers

What is RSpec Mocks?

I just start learn Ruby on Rails. When I research about RSpec test, I saw a recommend link about RSpec Mocks. However I don't know about the advantages of RSpec Mocks and how to use it. So can anyone summary about this.
sreang rathanak
  • 502
  • 1
  • 4
  • 15
0
votes
2 answers

Test module method with rspec-mocks

How to test config method in this module with Rspec 3 mocks? module TestModule class << self attr_accessor :config end def self.config @config ||= Config.new end class Config attr_accessor :money_url def initialize …
user1028432
  • 137
  • 1
  • 2
  • 15
0
votes
1 answer

Mocking a Java Interface in JRuby with RSpec-mock

I'm writing a simplistic wrapper for JDBC in JRuby. Essentially I want to have a wrapper class DBW that takes a connection string and an optional initialization block. require 'java' class DBW def initialize (connection_string,…
Emil L
  • 20,219
  • 3
  • 44
  • 65