infinitered / rmq

RMQ - RubyMotionQuery
MIT License
307 stars 52 forks source link

Tests for the merging of options in Animations #58

Open DiogoAndre opened 10 years ago

DiogoAndre commented 10 years ago

This came from PR #56

I would love to also help with this, but I'm not sure how to test the merging of options

Test bellow wouldn't really test it, right?

it 'should throb with custom durations' do
 @viewq.animations.throb(duration: 0.0, duration_out: 0.0).is_a(RubyMotionQuery::RMQ).should == true
end

I think we could pass any options there and the test would still pass.

Any ideas?

And thanks for RMQ, it's really easy to get going with and and quite useful!

twerth commented 10 years ago

Yeah, that doesn't really test it. If you actually run animations in tests, bad things happen. You'll see at the top of the file that animations are turned off.

You'd have to stub out the lower level and verify duration is being called (twice).

Like DHH, I don't like changing the code just to accommodate tests. Mocking and stubbing are fine though.

squidpunch commented 10 years ago

I have been looking into this a bit, and it can be a bit tricky indeed. You can use https://github.com/siuying/motion-stump for example - but I am finding a bunch of limitations. I was trying to do something similar with devices.

Using the readme for the project, I came up with this test.

  it 'should return the right value for simulator?' do
    @rmq.device.simulator?.should == true
    UIDevice.stub!(:currentDevice, return: stub(:model, return: 'this is a real device!'))

    # this would actually still fail because of the cache variables, but ignore that for now...
    @rmq.device.simulator?.should == false

    UIDevice.reset(:currentDevice)
  end

the problem here is, it really doesn't like the reset method:

RuntimeError: cannot remove method `__original_currentDevice' because it is a native method
    metareset.rb:26:in `restore_original_method:': device - should return the right value for simulator?
    metareset.rb:12:in `reset:'
    spec.rb:316:in `block in run_spec_block'
    spec.rb:440:in `execute_block'
    spec.rb:316:in `run_spec_block'
    spec.rb:331:in `run'

Additionally I found issues when trying to stub out userInterfaceIdiom like this

    UIDevice.currentDevice.stub!(:userInterfaceIdiom, return: UIUserInterfaceIdiomPad)

getting this

RBAnonymous76 0x99dee40> method `userInterfaceIdiom' created by attr_reader/writer or define_method cannot be called from Objective-C. Please manually define the method instead (using the `def' keyword).

I haven't dug any further than this, or checked if the mocking gem had any idea how to go about these things as of yet.

So any progress you happen to make, I'd love to know how you went about it. If I break any ground, I'll be sure to share it :)