Is it possible to test Angular without Karma? - ruby-on-rails

I'm pretty new to angular& we already have a working rails-stack with the jasmine-rails.gem - the tests that come with the example-app are not working, as
beforeEach(module('myApp'));
fails with a Can't find variable: module - and I got no idea where module and inject are supposed to be defined: Does anyone have an idea how to set up angular-tests to run standalone/outside of karma?

They come with angular-mocks.js, include that.
Get it at http://code.angularjs.org/

Related

Fitnesse: Could not find or load main class

When I run a test I get the below error:
Error: Could not find or load main class C:\GrowthEdition.QA\fitnesse\fitSharp\Runner.exe
The runner is in the specified location.
In the suitesetup I have defined the test runner:
variable defined: TEST_RUNNER=C:\GrowthEdition.QA\fitnesse\fitSharp\Runner.exe
What could be causing this issue, and how can I resolve it?
Many Thanks,
Rahul Dixit
please ignore.
I dont, know what I did differently, but it suddenly started working again.

Specifying the host in Rails performance tests

I have been trying to use the Rails profiling tools. I am using a very simple example taken from the docs at http://guides.rubyonrails.org/performance_testing.html that looks like this
require 'test_helper'
require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionDispatch::PerformanceTest
def test_homepage
get '/'
end
end
I then run the test using
rake test:profile
but it crashes with the following error
Error during failsafe response: undefined method `controller_name' for nil:NilClass
I suspect that the problem is that the app serves multiple domains and so simply using get '/' is not enough information to resolve the url back to a controller/action - it needs a host as well. However the usual ways of specifying a host (#host, #request.host, default_url_options[:host]) either don't work or cause another error (eg #request is nil).
I have also tried entering the full url. I have the different hosts defined as constants in the test environment so this looked something like
get "http://#{HOST_1}/"
In this case the rake task completed successfully but no profiling information appeared on the command line and no files were generated.
I haven't really used the profiling tools in Rails much so I am hoping I am missing something obvious. Any pointers would be much appreciated.
Cheers

Test page_caching with RSpec

Does anyone know how to test page_caching in Rails using RSpec without having to check to see if the cache file has been created for each request? Something more like Controller.performs_page_caching(:action).should be_true?
I've tried looking over the net, but I haven't found anything that works.
I have come up with a solution. You override the caches_page class method for the ApplicationController class and setup an after filter which sets a header 'x-page-cached' to true. Then in your test scripts include a macro for page_cached? which will check to see if response.headers['x-page-cached'] is true or not. Only do this for the test and development environments.
Seems like integration test. For example you could try write request spec and count somehow number of db queries.

Rails 3.1. What's the easiest way to make chaining dropdown selects?

I was trying to make work this:
http://chainselects.hypermediasoft.com/
But got error:
Routing Error
uninitialized constant ChainSelectsHelper
So i have to make some break and ask community - is there any easy way to make chaining select boxes for my application forms?
UPDATE:
Maybe i should make editions in some config files? I can see thist ChainSelectsHelper in vendor/plugins/ChainSelects/lib/app/helpers/chain_selects_helper.rb. But why my application can't see this? Any assets pipeline configs needed?
And got this error in model:
undefined method `acts_as_chainable' for #<Class:0x007fe387542780>
From the looks of it, it seems that you did not add this in the controller:
include ChainSelectsHelper
Keep in mind that modifications have to be made to both model and controller, as stated here.

Testing if a function is called using Mocha

In my current Rails 3 app, I'm doing some unit testing to make sure that calls to update S3 are only done under certain situations. I don't want to update S3 during tests, so I'm using Mocha to stub out the behaviour. Is there a way to make sure a function is called using mocha? I've taken a look at Expectations, and unless I'm doing it wrong, it seems I have to do:
object.expects(:function_name).once
However, this does not yield the desired results: This will flag an error if function_name is called twice(which is desired), it will NOT flag an error if it is only called once(as it should), but the problem is it WILL NOT flag an error if the function is called zero times. I need a way to make sure it is called. It seems like mocha should support this, so maybe I'm doing it wrong. Any help would be greatly appreciated.
***** CORRECTION:
Turns out that I was doing it right, except that the mocha_verify method wasn't being called automatically. For anyone who is having a similar problem, check out Ole Morten Amundsen's answer over here: Mocha Mock Carries To Another Test
or just
object.expects(:function_name).twice
alternatively, if it has differnet input you should test that
resultmock = mock
object.expects(:function_name).with(someobject).returns(mock)
resultmock.expects(:something).returns(true)
object.expects(:function_name).with(resultmock)
don't know if this helps, but it should give you a kick start. FYI: 'once' is default. Good luck, do TDD (=test-first) or mocking will be a pain :)
Be sure to load mocha last, so it is really being loaded, as in my answer here:
Mocha Mock Carries To Another Test
Try:
object.expects(:function_name).at_least_once
Have a look at the docs: http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000042

Resources