I want to define the following:
config.generators.stylesheets = false
config.generators.javascripts = false
config.generators.helper = false
But despite reading Ror's guide on the subject, I don't get where exactly the methods should go.
I think it belongs in config/application.rb:
module MyApp
class Application < Rails::Application
# Lots of stuff
# Generator configuration
config.generators do |g|
g.orm :active_record
g.template_engine :erb
g.test_framework :test_unit, fixture: false
g.stylesheets false
g.helper false
end
end
end
Related
How to change code in hooks to reset (iOS) app at specific scenario ?
means only to those scenario where tags mention as #reset
https://github.com/cucumber/cucumber/wiki/Hooks#tagged-hooks
UPDATED for Calabash 0.17 and run-loop 2.0.2
This project contains an example of how to use Cucumber tags and Before hooks to re-install apps and clear application data on simulators and devices.
https://github.com/calabash/ios-smoke-test-app/
In particular, see these two files:
ideviceinstaller wrapper
support/01_launch.rb
I won't reproduce the entire 01_launch.rb example here, but here are the hooks:
Before("#no_relaunch") do
#no_relaunch = true
end
Before('#reset_app_btw_scenarios') do
if xamarin_test_cloud? || LaunchControl.target_is_simulator?
ENV['RESET_BETWEEN_SCENARIOS'] = '1'
else
LaunchControl.install_on_physical_device
end
end
Before('#reset_device_settings') do
if xamarin_test_cloud?
ENV['RESET_BETWEEN_SCENARIOS'] = '1'
elsif LaunchControl.target_is_simulator?
target = LaunchControl.target
instruments = RunLoop::Instruments.new
xcode = instruments.xcode
device = instruments.simulators.find do |sim|
sim.udid == target || sim.instruments_identifier(xcode) == target
end
RunLoop::CoreSimulator.erase(device)
else
LaunchControl.install_on_physical_device
end
end
Before do |scenario|
launcher = LaunchControl.launcher
options = {
#:uia_strategy => :host
#:uia_strategy => :shared_element
:uia_strategy => :preferences
}
relaunch = true
if #no_relaunch
begin
launcher.ping_app
attach_options = options.dup
attach_options[:timeout] = 1
launcher.attach(attach_options)
relaunch = launcher.device == nil
rescue => e
RunLoop.log_info2("Tag says: don't relaunch, but cannot attach to the app.")
RunLoop.log_info2("#{e.class}: #{e.message}")
RunLoop.log_info2("The app probably needs to be launched!")
end
end
if relaunch
launcher.relaunch(options)
launcher.calabash_notify(self)
end
ENV['RESET_BETWEEN_SCENARIOS'] = '0'
# Re-installing the app on a device does not clear the Keychain settings,
# so we must clear them manually.
if scenario.source_tag_names.include?('#reset_device_settings')
if xamarin_test_cloud? || LaunchControl.target_is_physical_device?
keychain_clear
end
end
end
The key is recognize the difference between testing on simulators and devices and testing on the Test Cloud and locally.
You can reset the application settings and content before every Scenario using the RESET_BETWEEN_SCENARIOS env variable.
$ RESET_BETWEEN_SCENARIOS=1 cucumber
You can also implement a backdoor method to reset your app to a good known state. This example is a bit wonky and out of date, but I have used it to great effect in the past - it really speeds up tests - briar-ios-example You can do all kinds of things with backdoors: log users in/out, reset databases, wipe user preferences, add/remove files from the sandbox.
I'm kind of pulling my hair out on this one. I'm trying to test using rspec and Factory Girl (Ubuntu 13.10 and Rails 4). It seems as if Rspec doesn't see any of the Factory Girl stuff. Here's my spec_helper.rb:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'factory_girl_rails'
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.color_enabled = true
config.tty = true
config.formatter = :documentation # :progress, :html, :textmate
end
factories.rb:
FactoryGirl.define do
factory :exercise do
name 'New Exercise'
time 3
reps 7
weight 12
weight_unit 'kg'
factory :aerobic_exercise do
name 'Jumping Jacks'
kind 'Cardio/Aerobic'
end
factory :bodyweight_exercise do
name 'Pushups'
kind 'Bodyweight'
end
factory :cardio_exercise do
name 'Jumping Jacks'
kind 'Cardio/Aerobic'
end
factory :lifting_exercise do
name 'BB Shoulder Presses'
kind 'Weight Lifting'
end
end
end
and my failing spec:
#require 'test/spec'
require 'spec_helper'
describe Exercise do
describe 'Exercise properly normalizes values' do
it 'has weight and weight unit if kind is Weight Lifting' do
let(:exercise) { FactoryGirl.create(:lifting_exercise) }
exercise.should be_weight
exercise.time.should be_nil
end
it 'has time but not weight etc. if kind is Cardio' do
let(:exercise) { FactoryGirl.create(:aerobic_exercise) }
exercise.should be_time
exercise.reps.should be_nil
end
end
end
When I run rspec I get this error:
Failure/Error: let(:exercise) { FactoryGirl.create(:lifting_exercise) }
NoMethodError:
undefined method `let' for # <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f2f013b3760>
HELP!(please)
the let method isn't from FactoryGirl, it's from Rspec, and the issue is that let should not be nested within the it, it's meant to be used outside of it.
Given the way that you've written it, I think you should just use a local variable like this:
describe Exercise do
describe 'Exercise properly normalizes values' do
it 'has weight and weight unit if kind is Weight Lifting' do
exercise = FactoryGirl.create(:lifting_exercise)
exercise.should be_weight
exercise.time.should be_nil
end
it 'has time but not weight etc. if kind is Cardio' do
exercise = FactoryGirl.create(:aerobic_exercise)
exercise.should be_time
exercise.reps.should be_nil
end
end
end
Also, given that you've included FactoryGirl::Syntax::Methods in your spec_helper you don't need to prefix everything with FactoryGirl, you can just call it like this:
exercise = create(:lifting_exercise)
I hope that helps!
-Chad
Your issue is not RSpec and FactoryGirl not playing well together.
let is not part of an example's method group. Notice you have the let inside the it block. This should work
#require 'test/spec'
require 'spec_helper'
describe Exercise do
describe 'Exercise properly normalizes values' do
context 'with a lifting exercise' do
let(:exercise) { FactoryGirl.create(:lifting_exercise) }
it 'has weight and weight unit if kind is Weight Lifting' do
exercise.should be_weight
exercise.time.should be_nil
end
end
context 'with an aerobic exercise' do
let(:exercise) { FactoryGirl.create(:aerobic_exercise) }
it 'has time but not weight etc. if kind is Cardio' do
exercise.should be_time
exercise.reps.should be_nil
end
end
end
end
NOTE context is just an alias for describe.
I am trying to write test cases for controllers of an Ember (v1.0.0-rc.3) Application using Mocha and Chai. One of my controller is making use of another controller as follows
App.ABCController = Em.ObjectController.extend({
needs: ['application'],
welcomeMSG: function () {
return 'Hi, ' + this.get('controllers.application.name');
}.property(),
...
});
I wrote testCase as below:
describe 'ABCController', ->
expect = chai.expect
App = require '../support/setup'
abcController = null
before ->
App.reset()
ApplicationController = require 'controllers/application_controller'
ABCController = require 'controllers/abc_controller'
applicationController = ApplicationController.create()
abcController = ABCController.create()
describe '#welcomeMSG', ->
it 'should return Hi, \'user\'.', ->
msg = abcController.get('welcomeMSG')
expect(msg).to.be.equal('Hi, '+ applicationController.get('name'))
support/setup file is as follows
Em.testing = true
App = null
Em.run ->
App = Em.Application.create()
module.exports = App
Now whenever i try to run testcase i face error
"Before all" hook:
TypeError: Cannot call method 'has' of null
at verifyDependencies (http://localhost:3333/test/scripts/ember.js:27124:20)
at Ember.ControllerMixin.reopen.init (http://localhost:3333/test/scripts/ember.js:27141:9)
at superWrapper [as init] (http://localhost:3333/test/scripts/ember.js:1044:16)
at new Class (http://localhost:3333/test/scripts/ember.js:10632:15)
at Function.Mixin.create.create (http://localhost:3333/test/scripts/ember.js:10930:12)
at Function.Ember.ObjectProxy.reopenClass.create (http://localhost:3333/test/scripts/ember.js:11756:24)
at Function.superWrapper (http://localhost:3333/test/scripts/ember.js:1044:16)
at Context.eval (test/controllers/abc_controller_test.coffee:14:47)
at Hook.Runnable.run (test/vendor/scripts/mocha-1.8.2.js:4048:32)
at next (test/vendor/scripts/mocha-1.8.2.js:4298:10)
Please help me to resolve this issue. I will appreciate if someone provide me few links where i can study for latest ember.js application testing with mocha and chai.
Reading trough the docs I guess your problem is that your expect fails due to this to.be.equal. Try changing the assertion chain to this:
expect(msg).to.equal('Hi, '+ applicationController.get('name'))
Update
After reading your comment I guess the problem in your case is that when you do Ember.testing = true is equivalent to the before needed App.deferReadiness(), so it' obviously necessary to 'initialize' your App before using it, this is done with App.initialize() inside your global before hook. And lastly you call App.reset() inside your beforeEach hook's.
Please check also this blog post for more info on the update that introduced this change.
Hope it helps
In Bootstrap.php I have some custom routes using Zend_Controller_Router_Route_Regex.
Everything works fine except when user type in address bar a wrong link.
Ex :
http://mysite/en/1-some-article.html => This is a valid link that matches a ROUTE in Bootstrap.
But when user make a typo mistake like:
http://mysite/en/1-some-article.**html'** or http://mysite/en/1-some-article.**hhtml** , they are not match any ROUTE in Bootstrap, then Zend Framework throws an exception like : No route matched the request
Is there anyway to handle it, like redirecting to a custom page for "No matched routes"?
Any help will be appreciated. Thanks for advance!
Configuration (from comment below)
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
phpSettings.date.timezone = "Europe/London"
;includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = ""
;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
autoloaderNamespaces.Fxml = "Mycms_"
autoloaderNamespaces.Fxml = "Fxml_"
To make use of the ErrorController, you need to set the front controller throwExceptions attribute to false. Put this in your [production] configuration section
resources.frontController.params.throwExceptions = 0
See http://framework.zend.com/manual/1.12/en/zend.controller.exceptions.html and http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler.fourohfour.
I mentioned this in the comments above but you seem to have missed it (you have displayExceptions set to false but not throwExceptions).
I've been checking out RestKit and the GET works
#client.get("/?amount=5", delegate:self)
Does anyone know how to make a POST and receive the result?
The docs mention that it looks something like this -
#client.post("/ask", params:#paramvar, delegate:self)
What do you encapsulate #paramvar? I have tried it as an array, hash and even nil - however, none of them have yielded any results.
Take a look at the bubble wrap library. It includes some really nice HTTP helpers.
http://bubblewrap.io/
Found an example in the RubyMotion_Cookbook.
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_8/06_sendinghttppost
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
#window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
#window.rootViewController = RootController.new
url_string = "http://rubymotion-cookbook.herokuapp.com/post"
post_body = "bodyParam1=BodyValue1&bodyParam2=BodyValue2"
url = NSURL.URLWithString(url_string)
request = NSMutableURLRequest.requestWithURL(url)
request.setTimeoutInterval(30)
request.setHTTPMethod("POST")
request.setHTTPBody(post_body.to_s.dataUsingEncoding(NSUTF8StringEncoding))
queue = NSOperationQueue.alloc.init
NSURLConnection.sendAsynchronousRequest(request,
queue: queue,
completionHandler: lambda do |response, data, error|
if(data.length > 0 && error.nil?)
html = NSString.alloc.initWithData(data, encoding: NSUTF8StringEncoding)
p "HTML = #{html}"
elsif( data.length == 0 && error.nil? )
p "Nothing was downloaded"
elsif(!error.nil?)
p "Error: #{error}"
end
end
)
#window.makeKeyAndVisible
true
end
end
Source:
https://github.com/rubymotion/BubbleWrap
Insallation:-
in console run 'gem install bubble-wrap' or mention 'gem bubble-wrap' in Gemfile
Line to be added in 'app_delegate.rb'file(by this Bubblewrap api is available through out app):-
require 'bubble-wrap/http'
Sample code for syntax:-
BW::HTTP.get("https://api.github.com/users/mattetti", {credentials: {username: 'matt', password: 'aimonetti'}}) do |response|
p response.body.to_str # prints the response's body
end