similar to: using expects with (for Hash and Array)

Displaying 20 results from an estimated 1000 matches similar to: "using expects with (for Hash and Array)"

2007 Jun 21
2
expects with returns that returns the return value of the actual method
I''m trying to test some code that''s using active_merchant using the following test. What I''d like to be able to do is verify that purchase is called, however, rather than specifying the return value for purchase with returns, I''d like it to return the actual return value provided if you called the non mocked purchase method. Is this possible? def test_charge
2006 Sep 22
2
foo.expects(:blah).returns(10).then(11) syntax
I recently needed the behavior of my object to change on subsequent method calls so I added the syntax above. Here''s the diff of changes I made: Index: test/mocha/expectation_test.rb =================================================================== --- test/mocha/expectation_test.rb (revision 854) +++ test/mocha/expectation_test.rb (working copy) @@ -95,6 +95,12 @@
2007 Apr 12
15
Preview of Latest Mocha Changes
I''ve finally managed to find some time to do some serious work on Mocha. There are some code snippets on my blog (http://blog.floehopper.org/articles/2007/04/12/preview-of-latest-mocha-changes) showing the new functionality available in trunk (revision 128). I don''t don''t know how many people out there are using trunk, but it would be great to get some feedback on these
2008 Jan 28
9
Nested matchers
We''re encountering a failure with Mocha 0.5.6. We had this expectation: game_version.expects(:attributes=).with(:game_file => kind_of(GameFile), :game_id => @game.id) This expectation was passing with 0.5.5, but fails with 0.5.6. I added this test to parameter_matcher_acceptance_test.rb, which passes in 0.5.5 and fails in 0.5.6 def test_should_match_nested_parameters
2009 Feb 26
1
logistic regression - unequal groups in R
I am getting a repeated error when I try to run a logistic regression in R 2.8.1 >(glm(prop1~x1,data=glm1,family=binomial("logit"),weights=nt1)) Error in model.frame.default(formula = prop1 ~ x1, data = glm1, weights = nt1, : invalid type (list) for variable 'x1' x1 is multistate categorical (3 categories). 2 of the categories have 12 observation, one has 9. Is this what
2007 Jun 12
4
advice on new failures with 0.5.0
Hi all, We just updated to the latest version of Mocha and now we''re seeing a lot of odd test failures. If this isn''t the appropriate place for a question like this, please let me know. Say I have code like this in a controller: DataMonitor.toggle_notification! And I mock it like this: DataMonitor.any_instance.stubs(:toggle_notification!) This would work fine with Mocha
2007 Sep 21
5
Stubbing yielding methods
I''ve just been tying my brain in knots looking at bug #8687 ( http://rubyforge.org/tracker/index.php?func=detail&aid=8687&group_id=1917&atid=7477 ). I''ve been (1) trying to work out whether there is anything logically wrong with Mocha''s existing behaviour and (2) whether Mocha should support the requested functionality. It all centres around the use of the
2018 Mar 22
1
Calculate weighted proportions for several factors at once
Hi, I have a grouped data set and would like to calculate weighted proportions for a large number of factor variables within each group member. Rather than using dplyr::count() on each of these factors individually, the idea would be to do it for all factors at once. Does anyone know how this would work? Here is a reproducible example: ############################################################
2007 Dec 21
5
Mocha and rails 2.0.2?
Folks- With Rails 2.0.2, I''m seeing mocha failures where they did not fail with Rails 2.0.1 test_set_to_process_fail_in_transaction(FileRecordTest): NoMethodError: undefined method `ord'' for 63:Fixnum /home/wolpert/svn/rubylms/vendor/plugins/mocha/lib/mocha/class_method.rb:45:in `hidden_method''
2007 Sep 11
3
Expectations on portions of arguments called.
I''d like to create expectations on just portions of the arguments a function takes. For example, I want to verify that the a certain ActiveRecord association extension adds an order clause to the find options hash. Currently I simply check the entire argument structure, something like this def test_referring_journals_should_order_by_citation_count article =
2007 Sep 06
5
Removing/overriding/unstubbing a stub?
We''re using Mocha stubs to stub out a slow-performing network request in a Test::Unit class. But naturally, we don''t want to stub it out in the few tests that actually verify the functionality of that network request. Is there a way to do the stub in "setup", but override it for the few tests that need the original functionality? (I realize that in this case, the
2008 Jun 12
2
Google Group?
A number of people have had difficulties subscribing and/or sending messages to the existing mailing list. Also I have to spend quite a bit of time moderating spam and the mailman interface is pretty clunky. So I was contemplating setting a Google Group up instead. Does anyone have any objections? -- James. http://blog.floehopper.org http://tumble.floehopper.org
2007 Nov 04
3
Returning the mock associated with an expectation.
I was reading through the FlexMock docs and noticed the expectation method .mock, which returns the original mock associated with an expectation. It looks really handy for writing nice all-in-one mocks like: mock_user = mock(''User'').expects(:first_name).returns(''Jonah'').mock So I started playing around with mocha and found I could actually already do this!
2006 Dec 21
4
Stubbing Kernel#open
Anyone know how to stub Kernel#open? I''m trying to mock/stub an open-uri call, but it doesn''t seem to like it. Here''s the test code, and the failures: body = File.open(File.dirname(__FILE__) + ''/../fixtures/google_search_california.html'').read
2006 Oct 25
5
Mocha, Stubba and RSpec
Hi, I''ve been reading with interest the threads trying to integrate Mocha and Stubba with RSpec. So far, I''ve made the two changes in spec_helper.rb suggested, but discovered another one that neither of the archives mentions: If you use traditional mocking: object = mock or the stub shortcut : object = stub(:method => :result), you run into namespace conflicts with
2007 Sep 24
7
Parameter Matchers with optional params
Hi, Are there any docs for combining parameter matchers, or some way to define optional parameters? I''m trying to match something like: .find( 42 ) || .find( 42, {:conditions=>nil,:includes=>nil} ) Or for that matter, 42 followed by nothing or anything... Halp? I''ve tried different nested combos with any_of/all_of/anything, but getting lost trying. --Andrew
2006 Sep 11
4
Using rspec and mocha
I prefer to use rspec than test::unit for developing my apps. However I''ve found its mocking library to be pretty inflexible compared to Mocha. This isn''t really a surprise since rspec isn''t intended as a mocking framework, whereas Mocha is. So I''d like to play to both of their strengths and use rspec as my testing/specification framework and Mocha do to
2006 Sep 11
4
Using rspec and mocha
I prefer to use rspec than test::unit for developing my apps. However I''ve found its mocking library to be pretty inflexible compared to Mocha. This isn''t really a surprise since rspec isn''t intended as a mocking framework, whereas Mocha is. So I''d like to play to both of their strengths and use rspec as my testing/specification framework and Mocha do to
2007 Mar 30
7
problem with using any_instance
Hey all, I have a question with using mocha in my tests. In the same test file, I have two tests, <code> def test_a klass.any_instance.stubs(:method_name).returns("something") klass.new.method_name ... end def test_b ... klass.new.method_name ... end </code> where klass is some class when the tests run, test _a passes, but test_b had an error like this:
2007 Jun 08
4
Mocha 0.5 released
* Hamcrest-style parameter matchers * Values returned and exceptions raised on consecutive invocations * Yields on consecutive invocations * Multiple yields on single invocation * Invocation dispatch fixed * Deprecated returning result of a Proc -- James. http://blog.floehopper.org