I am trying to test out a simple local gem that I am working on but I am getting an error when testing the gem locally. I set the path to the local gem in my project's Gemfile.
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "rake"
gem "valet-tasks", path: "../../Gems/valet-tasks"
Rakefile
require 'valet-tasks'
The is the error I get:
rake -T --trace
rake aborted!
LoadError: cannot load such file -- valet-tasks
/Users/myuser/Sites/mysite/Rakefile:2:in `<top (required)>'
Here is how my valet-tasks Gem looks like:
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in valet-tasks.gemspec
gemspec
gem "rake", "~> 13.0"
lib/valet-tasks.rb
# frozen_string_literal: true
require 'rake'
require 'rake/tasklib'
require_relative "valet-tasks/version"
require_relative 'valet-tasks/hello'
module ValetTasks
class Error < StandardError; end
# Your code goes here...
end
lib/valet-tasks/hello.rb
module ValetTasks
module Task
include Rake::DSL if defined? Rake::DSL
class Hello < ::Rake::TaskLib
def initialize
super
namespace :hello do
desc 'Prints hello'
task :one do
puts 'Testing one two three'
end
end
end
end
end
end
ValetTasks::Task::Hello.new
I feel like everything is set up correctly. Could it be that this is not possible inside a Rakefile?
Looks like you are missing bundle exec
bundle exec rake -T
Related
Im working on w10 64bits
app.rb
require 'rubygems'
require 'sinatra'
require "sinatra/activerecord"
require 'sqlite3/sqlite3_native'
class App < Sinatra::Base
#configuraciones
set :root, File.dirname(__FILE__)
set :session_secret, 'super secret'
set :public_folder, File.dirname(__FILE__) + '/public'
set :layout, 'views/layouts'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'data.db'
)
enable :sessions
#before all requests
before do
headers['server'] = 'Ruby, Ubuntu'
end
end
rakefile.rb
require "sinatra/activerecord/rake"
require 'sqlite3/sqlite3_native'
require 'sinatra'
require './app'
gemfile
source "https://rubygems.org"
gem "sinatra"
gem "json"
gem 'sinatra-activerecord', '~> 2.0', '>= 2.0.9'
gem 'rake'
gem 'sqlite3'
so when i try to do db:migrate i cant do it, sqlite3 version 1.3.13
execute command
bundle exec rake db:migrate
rake aborted!
LoadError: cannot load such file -- sqlite3/sqlite3_native
C:/ruby/sinatra/Rakefile.rb:2:in `<top (required)>'
so i dont know what is exactly the problem need help
UPDATE
I change in rakefile.rb for only require 'sqlite3'
but know i get other error
rake aborted!
LoadError: cannot load such file -- sqlite3/sqlite3_native
C:/ruby/sinatra/Rakefile.rb:2:in `<top (required)>'
Caused by:
LoadError: cannot load such file -- sqlite3/2.5/sqlite3_native
C:/ruby/sinatra/Rakefile.rb:2:in `<top (required)>'
Try removing sqlite3_native from your rakefile.rb and just require sqlite3
My output when running my ruby cli file includes lines like:
D, [2018-11-17T15:33:29.481676 #45237] DEBUG -- : Patient Load (0.6ms) SELECT "patients".* FROM "patients"
I copied things from other sample projects for my environment, Gemfile, and Rakefile, and obviously something is set up to output this. How do I turn it off?
My gemfile:
source "https://rubygems.org"
gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'pry-nav'
gem 'activesupport'
gem 'nokogiri'
gem "activerecord"
gem "sinatra-activerecord"
gem "sinatra"
gem "sqlite3"
gem "rake"
gem "database_cleaner"
group :test do
gem 'poltergeist'
gem 'capybara'
gem 'rspec'
end
My rakefile:
# ENV['SINATRA_ENV'] ||= "development"
$LOADED_FEATURES << 'fake/active_support/core_ext/hash'
require_relative './config/environment'
require 'sinatra/activerecord/rake'
task :console do
Pry.start
end
My environment:
ENV['SINATRA_ENV'] ||= "development"
$LOADED_FEATURES << 'fake/active_support/core_ext/hash'
require 'bundler/setup'
Bundler.require
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: "db/#{ENV['SINATRA_ENV']}.sqlite"
)
require 'active_record'
require 'rake'
Dir[File.join(File.dirname(__FILE__), "../app/models", "*.rb")].each {|f| require f}
Dir[File.join(File.dirname(__FILE__), "../lib", "*.rb")].each {|f| require f}
Active record logs sql output in development mode by default. To disable it,
try adding this line before the section after it like so
ActiveRecord::Base.logger = nil
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: "db/#{ENV['SINATRA_ENV']}.sqlite"
)
I am running rspec and encountered the following error. I already looked for the similar posts but couldn't find the one that is relevant in this case.
'require': cannot load such file -- rspec/core/formatters/base_formatter (LoadError)
Ruby version: 2.4.3
Here is my Gemfile:
group :test do
gem 'database_cleaner', '~> 1.5'
gem 'factory_girl'
gem 'rack-test', require: 'rack/test'
gem 'rspec', '~> 3.5'
gem 'simplecov'
gem 'webmock'
gem 'timecop'
end
Here is the actual command:
/Users/<user_name>/.rbenv/versions/2.4.3/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/<user_name>/.rbenv/versions/2.4.3/bin/rspec _3.7.1_ /Users/<user_name>/Desktop/github/test_rspec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter
test_rspec.rb:
require 'spec_helper'
describe 'tests' do
include_context 'scenario'
# sample spec
end
I had a similar issue, so:
I removed my Gemfile.lock
re run bundle install
Trying to set up capybara/rspec for testing a simple sinatra app but keep getting a rack error.
hello.rb
require 'sinatra'
class App < Sinatra::Base
get "/" do
"hello hello!"
end
run! if app_file == $0
end
spec/hello_spec.rb
require File.join(File.dirname(__FILE__), '..', 'hello.rb')
require 'rspec'
require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
set :environment, :test
describe 'The Hello App' do
include Capybara::DSL
def setup
Capybara.app = App
end
it "says hello when browsing /" do
visit '/'
page.should have_content('hello')
end
end
Note, I also tried
def setup
Capybara.app = App.new
end
Which produced the same error.
Error:
C:\Sites\misc\qrgen>bundle exec rspec
F
Failures:
1) The Hello App says hello when browsing /
Failure/Error: visit '/'
ArgumentError:
rack-test requires a rack application, but none was given
# ./spec/hello_spec.rb:18:in `block (2 levels) in <top (required)>'
Finished in 0.374 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/hello_spec.rb:17 # The Hello App says hello when browsing /
Same error running with and without bundle exec. Any ideas?
Gemfile:
gem "sinatra"
gem "sinatra-contrib"
gem "sinatra-flash"
gem "slim"
gem "rspec"
gem "capybara"
gem "rack-test"
Hope this is useful for someone else trying to set up testing from the Sinatra documentation.
Changing
def setup
Capybara.app = App
end
to
Capybara.app = App
resolved the issue.
I've followed all of the steps that I've been able to find online for configuring Rails 3 with Rspec 2 and Mocha. In my Gemfile:
group :development do
gem 'rails3-generators'
gem "rspec", '>= 2.0.0.beta.19'
gem "rspec-rails", '>= 2.0.0.beta.19'
end
group :test do
gem "faker"
gem "rspec", '>= 2.0.0.beta.19'
gem "rspec-rails", '>= 2.0.0.beta.19'
gem "machinist", '>= 2.0.0.beta1'
gem "mocha"
gem "capybara", ">= 0.3.9"
end
And in spec/spec_helper.rb:
RSpec.configure do |config|
config.mock_with :mocha
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
end
Still, when I use the Rails generator...
rails generate scaffold foo name:string
...I get the following in spec/controllers/foos_controller_spec.rb:
def mock_foo(stubs={})
#mock_foo ||= mock_model(Foo, stubs).as_null_object
end
...which of course causes all specs to fail.
Does anyone know what I'm missing?
Thanks in advance.
In application.rb you'll need something like the following:
config.generators do |g|
g.test_framework :rspec
end
Further information available here:
http://guides.rubyonrails.org/generators.html#customizing-your-workflow