title: How do I test a script using RSpec?
body: <p>I'm writing a script that will be run using <code>rails runner</code> on production to make some one-time changes to our database. I want to be sure that the script works as expected before we run it, so I'm writing RSpec tests to verify its behavior while I write it.</p>
  
  <p>How can I invoke the script in my test examples? The script isn't a class or a module, so there aren't individual functions for me to test. Instead, the entire script will be loaded once, run from top to bottom, and then exited. I'm not sure how to invoke that from within an RSpec test.</p>
  
  <p>I'm looking for something like:</p>
  
  <pre class="lang-rb prettyprint-override"><code>describe "my script" do
    it "should create the correct record" do
      before_count = Orders.count
  
      rails runner my_script.rb # What goes here?
  
      expect(Orders.count).to eq(before_count + 1)
    end
  end
  </code></pre>