Capistrano - method_missing map - ruby

My deploy script throw error. I use capistrano and gem railsless-deploy
Error:
/var/lib/gems/1.9.1/gems/capistrano-2.15.5/lib/capistrano/configuration/namespaces.rb:193:in `method_missing': undefined method `map' for #<Capistrano::Configuration::Namespaces::Namespace:0x00000001a634b0> (NoMethodError)
My Capfile
require 'rubygems'
require 'railsless-deploy'
# load 'deploy'
load 'app/config/deploy'
My deploy.rb
#...more code...#
set :myfiles, ["path/to/file.ext","path/to/another/file.ext"]
#...more code...#
namespace :myfiles do
task :check do
myfiles.map do |file|
#...more code...#
end
end
end
ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
cap -V
Capistrano v2.15.5

You have a variable myfiles and then the scope a few lines later overrides that. That's why capistrano tries to send the map method to the namespace and fails. Change the list's name to something else like:
set :file_list, ["path/to/file.ext","path/to/another/file.ext"]
#...more code...#
namespace :myfiles do
task :check do
file_list.map do |file|
#...more code...#
end
end
end

Related

NoMethodError: undefined method `task' for Sinatra::Application:Class

This is the error I get when I run any rake command: undefined method 'task' for Sinatra::Application:Class
# Rakefile
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
require_relative './config/environment'
Dir.glob('lib/tasks/*.rake').each { |r| load r}
#lib/tasks/test_report.rake
namespace :test_report do
task :generate => :environment do
...
end
end
I run into the above error when I tried to run the command.
bundle exec rake test_report:generate
You're trying to use rake API, but it's not loaded. Add this on top of your file.
require 'rake'

Rake in Ruby: undefined method `namespace' for main:Object (NoMethodError)

I'm currently trying to run a Rake task in a Ruby project (No Rails). What I am trying to accomplish is to run a method from a file within my Ruby project. However I get the following error:
undefined method `namespace' for main:Object (NoMethodError)
I created a folder task that holds a test.rb file. Before I had it as test.rake but I think this was incorrect. I also created a Rakefile pointing to task/test.rb
For redeability, I'm using namespace: although I'll be honest I'm not sure if I even need it.
#Rakefile
task :default => [:test]
task :test do
ruby 'task/test.rb'
end
Here is the task.test.rb
require './src/lambda_function.rb'
class KMS
def initialize
end
def decrypt(key)
return "some password"
end
end
class SNS
def initialize
end
end
TEST_FORM_ID=123
namespace :test do
namespace :lambda do
desc 'Run the Lambda process function'
task :process do
LambdaFunctions::LambdaHandler.process(box_api: BoxApi.new,
form: TEST_FORM_ID,
sns: SNS.new,
kms: KMS.new)
end
end
end
What I'm I doing wrong?

Factory Girl: NameError: uninitialized constant Vserver

I am trying to setup the unit testing with Factory Girl and Rspec for my Sinatra application.
Gem file:
group :test do
gem "rack-test"
gem "fuubar"
gem "factory_girl"
gem "yard"
end
spec/factories/vserver.rb
require 'factory_girl'
FactoryGirl.define do
factory :vserver do
first_name "John"
last_name "Doe"
end
end
spec/spec_helper.rb
require File.join(File.dirname(__FILE__), "..", "app.rb")
%w{
rubygems
sinatra
dm-core
rack/test
uuid
factory_girl
rspec
pp
spec/factories/vserver
}.each { |r| require r }
set :environment, :test
# RSpec without Rails
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
spec/app_spec.rb
require './spec_helper.rb'
require 'factory_girl'
describe "Cdot" do
include Rack::Test::Methods
def app
StorageApi
end
it 'vserver' do
FactoryGirl.build(:vserver)
end
end
Issue: When I run the rspec file using the command: rspec app_spec.rb, I get the below error.
NameError: uninitialized constant Vserver
Help is much appreciated.
the code: factory :vserver do assumes that you have a class called Vserver that you are instantiating.
If you have such a class, then you need to include it in your spec.
If you don't have such a class, then you either need to rename the factory, or tell it what class it should be instantiating instead.

uninitialized constant BikeShare (NameError)

I'm trying to implement some simple testing in rspec for a gem I'm writing. When I comment out describe BikeShare do down to end and run the file, the file loads in and runs successfully. I'm sure it's something tiny I'm missing.
My test file is really simple and looks like this:
require 'spec_helper'
describe BikeShare do
it "should run" do
# response = BikeShare.new
# response.should_be present
end
end
When run, I get the error uninitialized constant BikeShare (NameError) at line 3.
My bikeshare.rb file looks like this, fairly simple:
class BikeShare
def initialize
response = JSON.parse(open("http://bayareabikeshare.com/stations/json").read)
#response = response["stationBeanList"]
end
def get_last_station
#response.last["id"]
end
end
My Rakefile looks like this:
require 'rubygems'
require 'bundler'
Bundler.setup
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new do |spec|
# spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/*_spec.rb'
end
task :default => :spec
Your tests arent aware of BikeShare.
You need to require the file that defines your BikeShare class. I dont use rspec but I think that you normally set up your testing environment in spec_helper.rb.

problem with task rake, ruby

I have got a task in rake that run my server sinatra , it doesn't work , the same script in ruby works. Why ?? can I run server sinatra in rake task??
task :server do
begin
require 'rubygems'
require 'sinatra'
rescue LoadError
p "first install sinatra using:"
p "gem install sinatra"
exit 1
end
get '/:file_name' do |file_name|
File.read(File.join('public', file_name))
end
exit 0
end
Create a class that is inherited from a Sinatra::Base class
#app.rb
require 'sinatra'
class TestApp < Sinatra::Base
get '/' do
"Test"
end
end
And then run your application from rake:
#Rakefile
$:.unshift File.join(File.dirname(__FILE__), ".")
require 'rake'
require 'app'
task :server do
TestApp.run!
end

Resources