At it’s simplest, the question is as follows: If I want test a method that calls another method with two values, and I want to check the value of the second argument but don’t know the value of the first argument, how can I do that? In essence, we have m1 -> calls m2(a, b), I want to test the value of b but I don’t know the value of a. If I knew both values, I could just use “expect(object).to_receive(:m2).with(a, b)” But what do I use if I don’t know what “a” should be (I know what class it should be, but #with is not using === to compare values, so that doesn’t help.
——— More detail that explains why I don’t know the value of “a" ——— I’m writing specs for some helpers. For one controller, I have a set of helpers like follows: form_editing_for_type(type, &block) ultimately generates a “form_for … fields_for …” with the block inside the #fields_for nav_buttons(f, options) generates Preview, Next, Cancel buttons for the FormBuilder object “f”; “options” has certain overrides for defaults; it must be called from the block passed to form_editing_for_type prev_buttom(f, options) these three helpers are called by nav_buttons only next_button(f, options) cancel_button(f, options) nav_button(f, name, default_label, disabled, options) this helper is called by the above three helpers only So far, I’m testing each helper separately (including the ones only called by other helpers. The problem I’m encountering is that I want to test that the “options” passed into “nav_buttons” is being passed on to “prev_button”, etc. I could do that with something like the following: it ‘passes “options” through” do @options = ... expect(self).to receive(:prev_button).with(ActionView::Helpers::FormBuilder, @options).and_call_original form_editing_for_type(@type) { |f| nav_buttons(f, @options) } end But, there are a few issues here. 1) Is “self” the correct object to expect #prev_button to be called against? 2) I don’t know the exact value of the first argument to :prev_button, so how do I tell expect that I don’t really know the value (I do know @options and I that’s what I’m checking)? ActionView::Helpers::FormBuilder does not work (apparently #with is not using “===“ to check the value). And then, the bigger issue: does it maybe make more sense, since the last four helpers are essentially private, to just test #nav_buttons for all the things that I would have tested the other four helpers for? This might better fit the idea of testing the desired result, not how the result is obtained. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/5A25DDD3-BCDF-4015-BBE0-1217A24E5735%40pobox.com.