Database Cleaner mongomapper and cucumber - ruby-on-rails

#/features/support/env.rb
...
require 'database_cleaner'
require 'database_cleaner/cucumber'
require 'database_cleaner/mongo_mapper/truncation'
DatabaseCleaner.strategy = :truncation
Before do
DatabaseCleaner.start
end
After do
DatabaseCleaner.clean
end
Result
Exception encountered by DatabaseCleaner in Cucumber After block: ActiveRecord::ConnectionNotEstablished
If I comment Before and After block - tests work fine without DatabaseCleaner
ree-1.8.7-2011.03
rails (2.3.12)
mongo_mapper (0.7.5)
cucumber (0.8.7)
cucumber-rails (0.3.2)
database_cleaner (0.6.7)

looks like it's still using ActiveRecord, try disabling it

Related

Capybara testing editablegrid features not working

Using editablegrid.net. Really like the layout and functionality.
The only problem is feature testing.
Nothing seems to work in capybara - page snap doesn't show the page content for the actual grid, matchers dont see content rendered in js.
I have to use an older phantom (v1.9.2) as support for capybara doesn't seem to be there on mac os x yet.
Anyone had any luck feature testing?
Things tried
page refresh: page.driver.browser.navigate.refresh
made sure turned on using turbolinks events for load
tried selenium and poltergeist
Setup details
versions
rails 4.1.0
capybara (2.9.1)
rspec (3.5.0)
phantomjs 192
selenium-webdriver (2.53.4)
poltergeist (1.5.1)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
$ phantomjs -v
1.9.2
UPDATE
updated versions
$ phantomjs -v
2.1.1
$ gem list | grep polter
poltergeist (1.10.0)
$ selenium-webdriver (2.53.4)
however when I do a simple test
visit 'address_books/'+user.address_book.id.to_s
page.save_screenshot("file1.png", :full => true)
sleep 4.seconds # just in case the delayed redraw takes time
page.save_screenshot("file2.png", :full => true)
expect(page).to have_content(/Person A.*2 8888 9999.*home/)
where this page includes an editablegrid that works fine in development (See example screen shot (http://imgbox.com/rqwx1vHe) ) doesn't render in the save screen shots ( http://imgbox.com/t1CG6hQa )
other notes
I tried selenium also, same problem : it is clear that the grid does not display.
I have used turbo links load for the event to trigger page load.
grid code
var editableGrid = null;
$(document).on('turbolinks:load', function() {
editableGrid = new EditableGrid("AddressBookGridJSON");
editableGrid.tableLoaded = function() { this.renderGrid("tablecontent", "testgrid"); };
editableGrid.loadJSON('/address_books.json');
// $.getJSON('/address_books.json', function(json) {
// editableGrid.load({"metadata": json.metadata, "data": json.data});
// console.log(editableGrid);
// });
});
UPDATE 2
index.json.jbuilder
json.set! :metadata do
json.array! #address_book.generate_view_table_meta_data
end
json.set! :data do
json.array! #contacts do |contact|
json.id contact.id
json.set! :values do
json.name contact.name
json.phone_number contact.get_presentation_number
json.phone_type contact.get_humanize_phone_type
json.action contact.get_url_to_view_delete
end
end
end
UPDATE 3
Data base cleaner code loaded
require 'database_cleaner'
RSpec.configure do |config|
config.before(:each) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
#DatabaseCleaner.strategy = :transaction
# if we use transaction the data is NOT saved during the actual rspec scenario. we must have commit
# during rspec so external compare processs can access data
# TODO make this conditional based on the compare plans process only
# tests will not have :nontransactional defined except compareplans testing
if self.class.metadata[:nontransactional]
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
end
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
end

Database_Cleaner with AR-Octopus not cleaning records

We have a project that is using the AR-Octopus gem using sharded databases. The problem we are running into is that the gem 'database_cleaner' is not cleaning records when using this setup, as we are consistently having leftover records in our test database that cause issues with our test suite.
I found this GitHub gist - https://gist.github.com/nowlinuxing/22ea0ab673a5622eb48d
Here is my database_cleaner config file
# spec/support/database_cleaner.rb
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
["master", *Octopus.config[Rails.env].keys].each do |shard|
DatabaseCleaner[:active_record, model: ActiveRecord::Base.using(shard)]
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end
Has anyone ever encountered this issue? If so, what did you do to resolve the issue? Just looking for some helpful insight.

rspec assert_equal no method error

undefined method 'assert_equal' for #<RSpec::Core::ExampleGroup::Nested_1:0x8d6f75c>
gem list
bundler (1.3.5)
diff-lcs (1.2.3)
rspec (2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
rspec-mocks (2.13.1)
test-unit (2.5.4)
spec_helper.rb
require './lib/checkout.rb'
require './lib/product.rb'
require 'rspec'
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
end
Try object.should eq('foo') or expect(object).to eq('foo') instead. As a side note, object.should == 'foo' will give you a Ruby warning when running with the -w flag.
Also, this is an assumption answer since you didn't give us any actual code.
Rather than change all your lines in a spec file you can add these at the top
require_relative '../spec_config'
and in that file put:
RSpec.configure do |config|
config.expect_with :minitest
end
because minitest has assert_equal method. Sorry I'm so late but I was just looking for answer myself to something and just happened to see this.
You can try object.should == "something". Here object means the object you want to test.

Using database_cleaner, mongoid and active_admin causes specs to fail with ActiveRecord::ConnectionNotEstablished

I have an existing project using mongoid, database_cleaner and rspec. I try to add active_admin, using the active_admin patches available. ActiveAdmin assumes it is in an ActiveRecord project, most specifically via its dependence on the meta_search gem.
When I go to run my specs, they all fail with the following error:
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# ./spec/support/database_cleaner.rb:12:in `block (2 levels) in <top (required)>'
The gem versions of the related libraries are as follows:
activeadmin (0.4.2)
database_cleaner (0.7.1)
mongoid (2.4.5)
meta_search (1.1.3)
activerecord (3.2.1)
The file that the tests are failing on, spec/support/database_cleaner.rb:
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
end
config.before(:each) do
DatabaseCleaner.clean
end
end
[moved from question]
It appears that database_cleaner attempts to autodetect the ORMs available to it in its initialization method
This can be pre-empted by changing the spec/support/database_cleaner.rb file like so:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner[:mongoid].strategy = :truncation
end
end
Calling the [] method in configuration overrides the autodetect such that ActiveRecord is no longer added.
Another workaround would have been to re-add a config/database.yml file with a sqlite3 configuration that the rest of the application ignored. Thankfully that isn't necessary.

FixtureReplacement with Cucumber

I am using Cucumber with Selenium, FixtureReplacement and DatabaseCleaner.
Funnily enough, my data I created with FixtureReplacement is not accessible from my tests.
I have added an own rails environment for selenium and I am using an own profile for my enhanced selenium features.
My cucumber setup for the selenium profile is:
Webrat.configure do |config|
config.mode = :selenium
config.application_environment = :selenium
end
Cucumber::Rails::World.use_transactional_fixtures = false
require "database_cleaner"
# Clean the database once when starting
DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :truncation
Before do
DatabaseCleaner.start
include FixtureReplacement
end
After do
DatabaseCleaner.clean
end
# this is necessary to have webrat "wait_for" the response body to be available
# when writing steps that match against the response body returned by selenium
World(Webrat::Selenium::Matchers)
FixtureReplacement works well, I have tested it in the Rails console.
I am running my selenium features with:
RAILS_ENV=selenium cucumber -p selenium features/enhanced/test.feature
Does anybody know a solution to this problem?
Best regards
I wonder if you are using Database Cleaner correctly? In my env.rb, I am using it like this:
Before do
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :truncation
end
This works for me when using Factory Girl.
This had nothing to do with Fixtures. I thought I cannot access my data, because I couldn't login.
The following fixed it:
Cucumber + selenium fails randomly

Resources