Questions tagged [expectations]

defines a set of expected and/or allowed method/constructor invocations on the mocked types/instances that have been made available to the test through mock fields and/or mock parameters (e.g., in JMockit).

121 questions
1
vote
1 answer

JMockit mock returns String instead of the List provided

Granted, it's been a while since I used JMockit, but I don't remember this kind of difficulty. I have a very simple test of some very simple code. But even though I set returns = List, the mocked method keeps returning just a String! Here's the…
Didjit
  • 785
  • 2
  • 8
  • 26
1
vote
1 answer

JMock expectations oneOf VS one difference

Is any difference in using one() or oneOf() in JMock? Cheat sheet says that: oneOf = The invocation is expected once and once only. exactly(n).of = The invocation is expected exactly n times. Note: one is convenient shorthand for exactly(1). In…
user1097772
  • 3,499
  • 15
  • 59
  • 95
1
vote
1 answer

jmock reset object state

I have HttpServletRequest mock object and I want to reset getHeader("someHeader") multiple times. For example: checking(new Expectations() { { allowing(request).getHeader("someHeader"); will(returnValue(null)); } }); Do something…
Jazz
  • 147
  • 1
  • 1
  • 5
1
vote
1 answer

PHPUnit: Expectations orders ignored in test when same stubbed method called multiple times with different arguments

I have a method (let's call it method2) that calls another method (let's call it method1) multiple times but with different arguments. Here is the class, MyClass.php:
Iam Zesh
  • 1,797
  • 2
  • 20
  • 42
1
vote
1 answer

should_receive in RSpec

As far as I know, should_receive is applied only to mock objects. What I want is to check, if a certain Class (not object) received a certain message, like: User.should_receive(:all).once How do I do that? UPD. Commonly, writing test for models and…
oldhomemovie
  • 14,621
  • 13
  • 64
  • 99
1
vote
1 answer

Nmock2 and Event Expectations

Im in the process of writing a test for a small application that follows the MVP pattern. Technically, I know I should have written the test before the code, but I needed to knock up a demo app quick smart and so im now going back to the test before…
Kildareflare
  • 4,590
  • 5
  • 51
  • 65
1
vote
1 answer

Jmockit expectations error

I have unit test case where I am using JMockit with expectations. Now when I run the test case alone, the test case passes. But when I run all test cases collectively, I get the: expected exactly 1 time, already invoked... error. I feel that some…
Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94
1
vote
1 answer

Ensure method was called with args at some point during test

I want to ensure that my Foo.bar method is called with true at some point during my test. So far I've only been able to assert against the first call to Foo.bar. I need to assert against any call. This is what I have so far but doesn't work: …
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
1
vote
2 answers

Rspec expect assignment (=) method to be called

I am writing some test where I would like to assert that some method actually calls the assignment method on an object which I have stubbed. I have tried doing this: expect(test_object.some_object[:whatever]).to receive(:=).with(some_data) #Does NOT…
Automatico
  • 12,420
  • 9
  • 82
  • 110
1
vote
3 answers

Ruby Rspec message expectations for a caught exception

Is there any way with Rspec to set an expectation for an exception that gets caught? I want to verify that MyException gets raised, but since I am catching the exception Rspec does not appear to know it ever happened. begin if success do good…
Conan Morris
  • 123
  • 1
  • 8
1
vote
1 answer

Ruby Mocha. List an objects expectations

With Mocha, is there a way to list current expectations on an object? e.g. x = Object.new x.expects( :foo ) # something like: puts x.expectations Sorry if this is a really obvious one.
Bungus
  • 592
  • 2
  • 11
1
vote
1 answer

How do I deal with rspec should_receive replacing the method when I want the method to actually be executed?

I'm new to using rspec should_receive and having a lot of problems because it "replaces" the method. For example: UserMailer.should_receive(:new_order).with(order) gives undefined method `deliver' for nil:NilClass, since rspec makes the…
pixelearth
  • 13,674
  • 10
  • 62
  • 110
1
vote
0 answers

To find expected value after performing some operations on array

I find problems in solving these kinds of questions Suppose there is an array A[1....n] and we can perform two kinds of operations on the array: Randomly Select Two Indexes p and q with p < q then swap A[p] with A[q] Randomly Select Two Indexes p…
jaig
  • 107
  • 2
  • 2
  • 6
1
vote
3 answers

RSpec update_attributes expectation failing, even though update works

I'm using what is largely a scaffold generated RSpec spec, which is failing but shouldn't be. Here is the spec: describe "PUT update" do describe "with valid params" do it "updates the requested invoice" do invoice =…
1
vote
2 answers

What is a good way to test a method that expects an HTML string?

foo.should_receive( :save ).with( html ) Where html is an HTML string, but I don't want to check against specific HTML because that would make the test brittle. Is there a way to check the length of the param that foo should receive? Is it possible…
B Seven
  • 44,484
  • 66
  • 240
  • 385
1 2 3
8 9