Ruby Method - FlexMock Backticks

I have Ruby code that uses inverse elements in several places and you want to test it. I am using FlexMock and want to mock this method somehow. I know that the Kernel ,: ` method , but cannot make it work with FlexMock. How would you do that? Here is a sample method that I want to test:

def foo
  result = `ls`
  if result.to_a.length > 0
    true
  else
    false
  end
end
+3
source share
3 answers

, , backticks Kernel.`, , FlexMock, , . , , , - ? ! , backtick .

, , . , pierr, , ​​ , . , , .

+3

flexmock, .

+1

Kernel.` "cmd" 

  `cmd` 

. :

it "should call system ls" do
  Kernel.should_receive(:`).with("ls")
  Kernel.` "ls"
end

rspec

0

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


All Articles