简体   繁体   中英

How do I use a dummy application to test a gem (preferably with Cucumber)?

I'm making a gem that will add some custom responders to an application's controllers. To test this, I'm going to need a dummy application sitting inside of a test directory that I can load and somehow generate views from.

I'd prefer to use Cucumber to test this gem, because that is what I'm most comfortable with having used it in the past.

How do I generate an application inside of my test directory like this? I will need at least a controller and a model, but views aren't necessary (the responder is only for JSON). Can I just generate a new Rails app within /features/support/dummy ? How would I run the dummy application from within my test suite?

At first, do not generate anything within features/support/ . That's the place for global hooks.

Your problem sounds not hard if I understood correctly. Here is my proposed steps.

  1. Create a demo directory in project root. New demo app will be under it.

  2. Create a ruby module/class under features/support/ , with methods to generate a demo app and delete it. The demo app will be simply some directories like app/contorllers for test purpose. Making a whole new Rails app sounds overkill.

  3. Create a tag for the Scenario which need generate app. Add Before and After hook for this tag to add and remove app for this Scenario, by calling the module/class in #2

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