Sunday 15 March 2015

ruby on rails - using rspec to test a controller in a gem -


Does anyone know that the brain with a RSPC using a controller of the brain using the app? I tried and without success

I have a controller in a gem:

  module mygem class PostsController & lt; :: Application controller deaf index @ posts = post.fund (all) @other_var = 10 end and end   

and I would like to make a test in my app such as spec / controller / posts_controller_spec .rb

  Describe the "contract" that describes "index", it receives "posts": assigns an index (post). To eliminate the Schlld_net b_nil it gets "another var": index acet_egell (10 assigns (other_worter)) end of end   

and my spec_helper.rb

  # This file sample has been copied / when you run the rails, generate the RSPC: 'ENV ["RAILS_ENV]] ==' test 'to the file.presspand_path (" ../../ Config / environment ", __FILE__) requires 'rspec / rails' 'rspec / autorun' # requires custom matte and macro Supporting Ruby files with OZ, etc., in spec / support / and its subdirectories. Dir [Rails.root.join ("spec / support / ** / * .rb")]. Each {| f | required f } Configure RSPC | config |   

I know that RSPC is not really for this, and ideas or options will also be helpful.

< Div class = "post-text" itemprop = "text">

A gem is a gem, the app is an app. They are different things.

I do not think the app in the gem A to mix the test Good practice.

Normally you do not need to test a gem because these are usually well-tested. If you really want to do this or there is a lack of gem test, gem thorn and draw it in the local, then open your test file and add yours then you can push it to improve this gem or your own gem Can end the version.

If you are writing your gem, put a test in the gem but not the app.

If you want to test some functionalities by adding gem in your app, then you can test the integrated effect, but no unit testing is required.

No comments:

Post a Comment