How would you do an integration test for a ruby project

I am trying to write tests for a ruby project.

I am struggling to start it. With Rails I can do an integration test to say click this button and then expect something.

Can I do something similar in ruby?

As in I want to be able to write the code and then start to make it work, or is it better to write out how I would do the commands on some paper and then test them?

for example I write all of this which none if it exists:

Product.brands.each do |brand|
  images = Product.images(brand, "image1")
  images.each do |image|
    file =


How will this code be run? From the command line?

Hi Andy,

Yes it will.

Ok. Start by thinking about the test phases. Using RSpec as an example, the rough outline might be:

describe "My command" do
  it "..." do
    # setup
    # execute
    # verify
    # teardown

You could then implement each phase as a method within the spec:



This would likely be a few ActiveRecord create! calls to get your data in the necessary state.


To run the command from within the test, you can call the shell command using the Ruby’s exec method.


Using Ruby’s file manipulation support, you could check that particular files exist, their sizes, extensions, etc. For example: expect(File.exist?("foo/bar.jpg")).to be(true)


The test should clean up after itself. (In Rails this is usually handled by wrapping everything in a transaction, or by the database_cleaner gem).

Hope this starts you off in the right direction.

You might also want to look at Aruba.