Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby testing expect a command to be ran
    primarykey
    data
    text
    <p>I testing my Rails application with Minitest and <a href="http://gofreerange.com/mocha/docs/" rel="nofollow">Mocha</a> for unit- and integration tests and want to test whether a commandline command gets called with certain parameters. </p> <p>Say, I have a class:</p> <pre><code>class Provisioning::Backup def create(path) system("tar -czf #{path} bar.tar.gz") end end </code></pre> <p>My test <em>only</em> wants to know if that command with these parameters gets run. And not whether it uses <code>system()</code> or its alternative <code>``</code>. Or even through resque and so on. I want to test the outsides, not the internal implementation. </p> <p>Hence I am not happy with my current solution in *test/integration/user_requests_backup_test.rb*:</p> <pre><code>class UserRequestsBackupTest &lt; ActionDispatch::IntegrationTest test "requests for a backup runs a backup-script" do contact = contacts(:harry) site = contact.sites.first Provisioning::Backup.expects(:system).with("tar -xzf foo bar") post "/v1/sites/#{site.id}/backups" assert_response :success end # backup is already pending # backup fails end </code></pre> <p>This works, but asserts implementation rather then behaviour because <code>Provisioning::Backup.expects(:system).with("tar -xzf foo bar")</code> assumes too much about the inner workings and will fail as soon as I move this to e.g. resque. </p> <p>What are my other options? Is there a way to mock or stub and expect <code>system</code> on a lower level? Is there maybe a pattern or gem that allows mocking out and expecting commands in a more generic way?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload