Questions tagged [rr]

RR (Double Ruby) is a test double framework that features a rich selection of double techniques and a terse syntax.

32 questions
26
votes
10 answers

What is the best practice when it comes to testing "infinite loops"?

My basic logic is to have an infinite loop running somewhere and test it as best as possible. The reason for having an infinite loop is not important (main loop for games, daemon-like logic...) and I'm more asking about best practices regarding a…
marcgg
  • 65,020
  • 52
  • 178
  • 231
6
votes
3 answers

Stubbing when an object's constructor builds another object

So I've got some code that, grossly simplified, looks like this: class B def initialize opts @opts = opts end end class A def initialize opts # defaults etc applied to opts @b = B.new opts end end In other words, when I…
lambshaanxy
  • 22,552
  • 10
  • 68
  • 92
5
votes
1 answer

Programmatic access to old and new values of a watchpoint in gdb

What I'm really doing is trying to set a watchpoint on the setting or clearing of a single bit. I do that by setting a watchpoint on the word containing the bit, then making it conditional on *word & mask (for setting, or (~*word) & mask for…
sfink
  • 1,726
  • 1
  • 17
  • 22
3
votes
1 answer

Ruby Unit testing techniques, Mocking and Stubbing

I've been recruited as a SW Dev and I'm trying to get into Unit Testing with RSPEC and RR in ruby but having an hard time deciding on a specific strategy mainly because I was assigned to write unit tests to a code which is already written. Consider…
Mikey S.
  • 3,301
  • 6
  • 36
  • 55
3
votes
1 answer

How do you mock a method with a block using RR (double ruby) on Rails 3

I am using the Koala gem to make facebook requests and i have the following code: @graph = Koala::Facebook::API.new(oauth_token) @graph.batch do |batch_api| #... do stuff here end I want to mock out the batch call to simulate the stuff we…
trcarden
  • 881
  • 1
  • 9
  • 17
3
votes
1 answer

Stub (...) received unexpected message (...) with (no args)

I try to write a test using RR. What I need is a stub of a model object. describe ApplicationController do subject(:application_controller) { ApplicationController.new } let(:messages) { ['a1', 'a2', 'a3' ] } …
ciembor
  • 7,189
  • 13
  • 59
  • 100
2
votes
1 answer

RSpec view test using RR failing - undefined method stub

I am using Rails 3.1, RSpec 2.6, and rr 1.0.4 and I get a NoMethodError: undefined method `stub' for # I am trying to utilize the RSpec test below to test my "Activities" show.haml view. If I change my spec_helper.rb file…
Jonathan Katon
  • 746
  • 1
  • 6
  • 14
2
votes
1 answer

Rspec actions that change the DB

I'm a bit confused with the behavior of rpsec tests involving controller methods that affect the DB. I have seen many examples of rspec tests that involve POST's and DELETE's where people check to see that an object was created or deleted. In most…
Danny
  • 4,724
  • 6
  • 42
  • 55
2
votes
2 answers

mocking in Ruby: mocks are sticking around between tests

I'm using RR as the mocking framework for a personal project of mine. I've been using it to mock the new method for some classes and when I run the tests they pass fine, but when I run ALL of the tests I run into a problem where it seems like the…
Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150
2
votes
1 answer

Java ArrayList in ArrayList

I have a question about an ArrayList inside an Arraylist. It's about multiple worlds with multiple spawns. I want to check every world one by one and save all the spawns of that world in an ArrayList. At the end I have an ArrayList with on every…
user3013897
  • 35
  • 1
  • 4
1
vote
1 answer

ruby rr: How to stub/mock built-in variables like $?

While writing a unit test for following: def foo() popen_response = "" IO.popen(@packaging_cmd, :err=>[:child, :out]) {|io| popen_response = io.read } rc = $? @log.debug{"Response from IO.popen() : #{popen_response}. rc: '#{rc}'"} if…
Kashyap
  • 15,354
  • 13
  • 64
  • 103
1
vote
1 answer

How do I write a spec to verify the rendering of partials?

I'm using rr (the mocking framework) and rspec with ruby-on-rails. Also, I'm using the collection short hand for partial rendering. My question: How do I correctly fill out the the following view spec? describe 'my_view' do before(:each) do …
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
1
vote
1 answer

yield to a block using rr

I'm trying to test the following code using rr: response = RestClient.get(url, {:params => params}){|response, request, result| response } In vanilla rspec, you would do something like this: RestClient.should_receive(:get).with(url, {:params =>…
Raphael
  • 1,701
  • 15
  • 26
0
votes
1 answer

How do I create and assign a stub object using RR?

I am trying the RR double framework for the first time and am a bit stuck on how to convert my existing RSpec stubs. I see how I can use double graphs in the documentation for the same result as RSpec's stub_chain, but how do create a stub/mock…
Eric M.
  • 5,399
  • 6
  • 41
  • 67
0
votes
1 answer

Rails RR UnitTesting: Problems with mocking an ActiveRecord model method

Consider the following class and methods: (This class is obviously much more complete, but for the sake of this thread...): class Order < ActiveRecord::Base def check if (self.user.phone == "55555555") do self.a_certain_method …
Mikey S.
  • 3,301
  • 6
  • 36
  • 55
1
2 3