简体   繁体   中英

Set up cucumber to test sinatra app using watir

I'm developing a sinatra app, and I'd like to test it using cucumber and watir. My problem is that I'm not sure how to set up my env.rb file to run the sinatra app, all the examples I've found use webrat or capybara or something else that isn't watir. Is there a way to start my sinatra app from cucumber without using webrat or another testing framework that isn't watir, or should I just start my sinatra app manually before running my tests?

env.rb executes an arbitrary Ruby code as a part of Cucumber setup, so you should be able to start your app or do whatever else you need. Try:

require 'YourApp'
YourApp.run!

Having said that, it might not be the most logical place to do. An automated build cycle for a web app usually consists of the following steps:

  1. Build: compile, copy necessary files, package a binary, etc.
  2. Run unit tests
  3. Deploy: put the application on a target server
  4. Run integration/feature tests

Cucumber and Watir are all about Step 4; therefore, env.rb usually starts a browser. What you are trying to do belongs logically in Step 3, IMHO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM