Therefore, I cannot make fun of a method implemented in C

Take a look at https://github.com/rails/rails/commit/1408b942d9c2c131a1cdcab97f49d74ce84dae38

I thought that taunting means you can mock any method. I did not know that the methods implemented in C cannot be mocking. Why?

I guess this means that I really don't understand how mocking works.

+4
source share
2 answers

This has nothing to do with the mocking methods in C and only applies to the dependecy method.

If you read carefully, the commit states that mocking Time.now no longer affects Date.today .

In Ruby 1.8.7, Date.today was implemented in Ruby and called Time.now . In the new Ruby, Date.today is in C and does not call Time.now .

+4
source

Not sure about this because Double Ruby https://github.com/btakita/rr seems able to do this:

 require 'rubygems' require 'test/unit' require 'rr' extend RR::Adapters::RRMethods class MockTest < Test::Unit::TestCase include RR::Adapters::TestUnit def test_can_mock_c_method a = [1,5,3] mock(a).sort{'foo!'} assert_equal 'foo!', a.sort end end 

This uses MRI 1.8.7, and as far as I can tell, sorting # sort and Array # is implemented in C. Please correct me if I am wrong.

0
source

Source: https://habr.com/ru/post/1343447/


All Articles