Loading miniskirt with Spork TestUnit - ruby-on-rails

I really like Miniskirt and Minitest but I am having issues loading the factories.rb file on each run using spork server. It goes:
cannot load such file -- factories (LoadError)
My factories.rb file is located in the /test directory along with my test_helper.rb.
Any tips would be appreciated.
require 'rubygems'
require 'spork'
Spork.prefork do
...
require 'factories'
end

It took me a little trial and error to get everything to work, but I fixed it by switching to spork-minitest and using the master branch of guard-minitest. Here's my test suite:
group :test, :development do
gem 'capybara'
gem 'database_cleaner'
gem 'awesome_print'
gem 'turn'
gem 'guard'
gem 'guard-spork'
gem 'guard-minitest', github: 'guard/guard-minitest'
gem 'guard-livereload'
gem 'terminal-notifier-guard'
gem 'capybara_minitest_spec'
gem 'rb-fsevent', '~> 0.9.1'
gem "spork-minitest", git: "https://github.com/semaperepelitsa/spork-minitest.git"
gem 'miniskirt'
gem 'minitest-spec-rails'
end
Thanks for the help anyway.

Related

Loading configuration and route.rb twice and produces error

Rails.application.initialize! command in environment.rb loads the files including route.rb twice when executing test using rspec. It works when executing it in production environment and route file is loaded exactly once. What may be the issue. I am using gemset
group :development,:test do
gem "rails-erd"
gem 'letter_opener'
gem 'spring'
gem 'faker'
gem 'pry-rails'
gem 'pry-byebug'
gem 'rspec-rails'
gem 'factory_girl_rails'
end

Don't know how to build task - Cucumber

In cucumber, my seed data is loaded up via several rake tasks. None of which are working:
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
Rake::Task['alchemy:db:seed'].invoke
When I run one of spree's rake tasks I get:
Don't know how to build task 'db:load_dir' (RuntimeError)
When I run one of alchemy's rake tasks I get:
Don't know how to build task 'alchemy:db:seed' (RuntimeError)
The testing database exists. I have ran rake db:test:prepare and it appears to be setup from my inspections. Lets move onto the hooks:
# features/support/hooks.rb
Before do
load File.join(Rails.root, 'db', 'seeds.rb')
end
This goes to the root and gets me the seed data. I decided to try this:
# features/support/hooks.rb
before do
# load File.join(Rails.root, 'db', 'seeds.rb')
Rake::Task['alchemy:db:seed'].invoke
end
The error was:
Don't know how to build task 'alchemy:db:seed' (RuntimeError)
I'm unable to figure out why the rake tasks are not working in cucumber.
My Gemfile is as follows:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.0.6'
gem 'pg'
gem 'redis-rails'
gem 'redis-rack-cache'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'thin'
gem 'durable_decorator_rails', github: 'jumph4x/durable_decorator_rails'
gem 'newrelic_rpm'
gem 'rake'
gem 'spree', '2.2.2'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-2-stable'
gem 'alchemy_cms', github: 'magiclabs/alchemy_cms'
gem 'spree_alchemy', github: 'tesserakt/spree_alchemy'
group :doc do
gem 'sdoc', '~> 0.4.0'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
group :test do
gem 'simplecov', require: false
gem 'cucumber-rails', require: false
gem "cucumber-websteps"
gem 'database_cleaner'
gem "selenium-webdriver"
gem "capybara-webkit"
end
group :development, :test do
gem "factory_girl_rails", "~> 4.0"
gem "rspec-rails"
gem 'rspec-its'
gem 'shoulda-matchers', require: false
end
And this is my env support file:
# features/support/env.rb
require 'cucumber/rails'
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise 'You need to add database_cleaner to your' \
'Gemfile (in the :test group) if you wish to use it.'
end
Cucumber::Rails::Database.javascript_strategy = :truncation
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :chrome
Rake doesn't load tasks by default, you can check for yourself:
irb(main):002:0> require 'rake'
=> true
irb(main):003:0> Rake::Task.tasks
=> []
So it doesn't "know" how to run your task. You need to tell Rails to load them:
Rails.application.load_tasks
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
It seems that the test database is missing. So as already written in the comment above, the solution is to create the database and run the migrations with
RAILS_ENV=test rake db:setup
Happy to help :)

Ruby on Rails, uninitialized constant Test::Unit::TestCase::Assertions (NameError)

Like the headline said, I am getting the aforementioned error when I try to run my rspec tests. The exact error is (word wrapped for readability):
/.rvm/gems/ruby-1.9.3-p374/gems/test-unit-2.4.8/lib/test/unit/testcase.rb:93:in
`<class:TestCase>': uninitialized constant
Test::Unit::TestCase::Assertions (NameError)
The main fix for this problem on the internet seems to be to remove the 'turn' gem, however I don't have the turn gem loaded. Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'devise'
gem 'therubyracer'
gem 'mysql2'
gem 'cucumber'
gem 'email_spec'
gem 'cancan'
gem 'rolify'
gem 'libv8'
gem 'simple_form'
group :test, :development do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'test-unit'
end
group :test do
gem 'cucumber-rails', :require => false
gem 'capybara'
gem 'database_cleaner'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass'
gem 'sass-rails', '~> 3.2.3'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
The part of my code that the test seems to be choking on is when I have this line in my require 'rspec/rails' in my rspec_helper.rb file.
This project used to run rspecs flawlessly. It's only when I did a reinstall of my OS that it began to behave badly.
Any help is greatly appreciated
Since your are not generating a new app, remove the line
gem 'test-unit'
from your Gemfile and remove the gems turn and minitest, followed by a bundle update.
Answer: If you look in my Gemfile, you see a requirement in my group :test, :development for gem 'test-unit'. I commented that out and it works like a charm. Why and how this works I have no idea, if someone would mind explaining go right ahead.

No such factory: user (ArgumentError) but... it is defined. and using find_definitions() just finds duplicates... =\

So, I recently moved to bundler, and I'm having issues getting everything working again.
when I run bundle exec rake test:units, I get this error:
....../gems/factory_girl-1.2.4/lib/factory_girl/factory.rb:327:in `factory_by_name': No such factory: user (ArgumentError)
and, I saw in a another stack overflow post that someone fixed the problem by adding
FactoryGirl.find_definitions
but, that errors in saying that I have duplicate definitions (which I don't, cause search)
I even tried having only one factories file. but the error continued.
top of test_helper:
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require "bundler/setup"
Bundler.require(:test)
test group in gem file
group :test do
gem "cucumber", "~>0.10.3"
gem "cucumber-rails", "0.3.2"
gem "launchy"
gem "hpricot"
gem "gherkin", "~>2.4.0"
gem "capybara", "0.4.1.2"
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.2"
gem "rspec-core"
gem "rspec-expectations"
gem "webrat", "0.7.0"
gem "database_cleaner"
gem "factory_girl", "1.2.4"
gem "shoulda"
gem "awesome_print"
gem "cobravsmongoose"
end

rake not running unit tests

I've upgraded my app from using config.gem to a Gemfile with bundler and have noticed that my unit tests have now stopped running. It's a bit strange and I'm not entirely sure where to start looking.
When I run rake test:units --trace I can see my environment being setup and it lists the files it intends to execute, but then it just returns.
It does the same thing if I try to run one individual file using something like: rake -I"lib:test" test/unit/foo.rb or using autotest.
It's all very strange. It's as if the files are being loaded but the actual unit tests are not being run.
I'm using shoulda and fast_context and I thought these might be the problem but if I include a unit test using the standard def test_ syntax it still doesn't get run so I don't think it's those.
Any hints or pointers would be greatly appreciated. I feel like I'm coding blind until I can get them working again!
So here's where I am now:
My reasons for using bundler are for installing dependencies on heroku and because I wanted to use a gem sourced from a git repo on github. The long and the short of it is that I've removed the preinitializer for bundler and have gone back to using config.gem. To get around the fact that I can't use a github repo using config.gem I've pushed out my own copy to rubygems. Was this the right move?
Here's the preinitializer.rb
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
"Run `gem install bundler` to upgrade."
end
begin
# Set up load paths for all bundled gems
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
Bundler.setup
rescue Bundler::GemNotFound
raise RuntimeError, "Bundler couldn't find some gems." +
"Did you run `bundle install`?"
end
I don't know how the .gems file would be useful because it's a heroku only thing and I'd have to hunt through git for it, but here's my gemfile.
source :gemcutter
gem 'rails', '2.3.9'
gem 'pg'
gem 'minitest'
gem 'RedCloth'
gem 'erubis'
#gem 'memcached'
gem 'daemons'
gem 'resque'
gem 'inherited_resources', '1.0.6'
gem 'clearance', '0.8.8'
gem 'acl9'
gem 'sprockets'
gem 'aws-s3'
gem 'paperclip', '2.3.1.1'
gem 'rmagick', '2.12.2'
gem 'jonnii-cheddargetter', '0.1.3'
gem 'attribute_normalizer'
gem 'formtastic', '1.1.0.beta'
gem 'will_paginate', '2.3.14'
gem 'hoptoad_notifier'
gem 'mixpanel_client'
gem 'sunspot'
gem 'websolr-sunspot_rails'
gem 'geokit'
gem 'ri_cal'
gem 'jonnii-yelp'
group :development, :test do
gem 'test-spec'
gem 'shoulda'
gem 'redgreen'
gem 'factory_girl'
gem 'populator'
gem 'faker'
gem 'ZenTest'
gem 'autotest-rails'
gem 'webrat'
gem 'cucumber'
gem 'cucumber-rails'
gem 'database_cleaner'
gem 'parallel'
gem 'hydra'
gem 'heroku'
gem 'taps'
gem 'ruby-prof'
gem 'treetop'
gem 'rspec'
gem 'rspec-rails'
end
Got the same problem.Just remove the gem 'hydra' will get the unit test back to normal
Do you have this at the end of your config/boot.rb file:
class Rails::Boot
def run
load_initializer
Rails::Initializer.class_eval do
def load_gems
#bundler_loaded ||= Bundler.require :default, Rails.env
end
end
Rails::Initializer.run(:set_load_path)
end
end
(from http://gembundler.com/rails23.html)
I recently had trouble running specs for a project. The reason was that I was missing a line from config/application.rb. Nowadays that line pops in by default when you create a new rails 3 project, but if your project has been initialized some time ago it might be missing.
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)

Resources