开发者

Run cucumber tests on heroku

开发者 https://www.devze.com 2023-01-15 22:36 出处:网络
I am thinking of running my cucumber tests on my rails app when it is running on heroku. Is this a sane way to check for diffe开发者_如何学JAVArences between development environment and deployment env

I am thinking of running my cucumber tests on my rails app when it is running on heroku. Is this a sane way to check for diffe开发者_如何学JAVArences between development environment and deployment environment?

Does anybody have any experience of this kind of scenario? Rake -T tells me "cucumber rake task not available (cucumber not installed)" even though I have specified cucumber-rails in my .gems file. Am I approaching this from the wrong angle?

Any ideas or suggestions?


You could use a seperate Heroku instance and deploy your app to there. You should then be able to run your tests via heroku rake.

You can use the --app parameter to the heroku command line to choose which instance to run commands on. Just dont delete your prod database by accident.


That would require the creation, modification and subsequent removal of a test database, and since Heroku ignores the database.yml file, this would not be possible at all.

You may try running your app in the testing environment by setting it in the console, and then you may be able to run tests

heroku config:add RACK_ENV=test

but even if you get this to work, say goodbye to your production database as I'm pretty sure Heroku will again override the database.yml and use the database it automatically assigned to your app.

You may also consider creating a second app on Heroku just for testing.


Is the cucumber gem also in your Gem manifest?


Since running tests directly on Heroku seems to be not so trivial, I resorted to directing local test to the Heroku app, using HTTParty calls instead of usual Capybara calls.

This can work nicely, at least for integration tests.

For example, this is the method I use in step definitions when running conventional local tests against the local app:

  def my_http_request(httpmethod, path, body = '')
    send httpmethod, path, body
  end

and this is the method I use when running local tests against the Heroku app:

  def my_http_request(httpmethod, path, body = '')
    options = body.blank? ? { :headers => {"Content-Length" => "0"} } : { :body => body }
    @last_response = HTTParty.send httpmethod, 'https://lit-*****-6305.herokuapp.com' + path, options
  end

I load one or the other into the Cucumber World, based on a specific option passed to Cucumber itself and set in a relevant profile (so that I can simply call cucumber -p heroku when I want to test against Heroku).

Of course, in the second case I also have to take care of initializing the Heroku database before each scenario, calling for instance something like this in a 'before' hook:

  def start_my_heroku_tests
    @@db = PGconn.open(:host => 'ec2-54-**-****-44.compute-1.amazonaws.com', :port => 5432, :dbname => 'd4d********rmi4k', :user => 'llcm*******jcyh', :password => '7FN_************gcxq')
    @@db.exec "TRUNCATE sources"
    @@db.exec "TRUNCATE posts"
  end
0

精彩评论

暂无评论...
验证码 换一张
取 消