Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Test Environment  #92

@LauraKirby

Description

@LauraKirby

I am not sure if this is a feature request, bug or user error.
issue:

issue: CassandraMigrations::Cassandra.create_keyspace!('test') does not create keyspace. Therefore, the test keyspace must be manually created with RAILS_ENV=test rake cassandra:drop cassandra:create cassandra:migrate. After manual creation, I can successfully run bundle exec rspec, which includes writing and reading from CassandraMigrations::Cassandra.

ideal solution: ability to run something like what cassandra:drop cassandra:create cassandra:migrate offers; however, within ./spec/rails_helper. This might be built but I don't think it is working properly, see setup below.


Using Rspec, I would like to create the keyspace, run migrations and drop the keyspace before and after the suite is run. After each test, I would like to clear out the data in all the tables. Below is my attempt at doing this:

./config/cassandra.yml

common: &common
  port: 9042
  replication:
    class: 'SimpleStrategy'
    replication_factor: 1

test:
  <<: *common
  keyspace: analytics_test
  hosts:
    - cassandra

./spec/rails_helper

require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'active_support/all'
require 'cql'
require 'cassandra_migrations'

RSpec.configure do |config|
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = false

  # The different available types are documented in the features, such as in
  # https://relishapp.com/rspec/rspec-rails/docs
  config.infer_spec_type_from_file_location!

  config.before(:suite) do
    # create keyspace
    CassandraMigrations::Cassandra.create_keyspace!('test')
    # run migrations
    # ...
  end

  config.around(:each) do |example|
    # clear data from tables
    # ...
  end

  config.after(:suite) do
    # remove keyspace and all corresponding test data
    CassandraMigrations::Cassandra.drop_keyspace!('test')
  end
end

run: bundle exec rspec

Keyspace 'analytics_test' does not exist : Keyspace 'analytics_test' does not exist

An error occurred while loading ./spec/models/transfer_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

CassandraMigrations::Errors::UnexistingKeyspaceError:
  Keyspace analytics_test does not exist. Run rake cassandra:create.
# /usr/local/bundle/gems/cassandra_migrations-1.0.0/lib/cassandra_migrations/cassandra.rb:63:in `rescue in use'
# /usr/local/bundle/gems/cassandra_migrations-1.0.0/lib/cassandra_migrations/cassandra.rb:59:in `use'
# /usr/local/bundle/gems/cassandra_migrations-1.0.0/lib/cassandra_migrations/cassandra.rb:20:in `start!'
# /usr/local/bundle/gems/cassandra_migrations-1.0.0/lib/cassandra_migrations/railtie/initializer.rb:14:in `<module:CassandraMigrations>'
# /usr/local/bundle/gems/cassandra_migrations-1.0.0/lib/cassandra_migrations/railtie/initializer.rb:12:in `<top (required)>'
# /usr/local/bundle/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
# /usr/local/bundle/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
# /usr/local/bundle/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
# /usr/local/bundle/gems/cassandra_migrations-1.0.0/lib/cassandra_migrations/railtie.rb:6:in `block in <class:Railtie>'
# /usr/local/bundle/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec'
# /usr/local/bundle/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run'
# /usr/local/bundle/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers'
# /usr/local/bundle/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers'
# /usr/local/bundle/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:5:in `require'
# ./spec/rails_helper.rb:5:in `<top (required)>'
# ./spec/models/transfer_spec.rb:1:in `require'
# ./spec/models/transfer_spec.rb:1:in `<top (required)>'
# ------------------
# --- Caused by: ---
# Cassandra::Errors::InvalidError:
#   Keyspace 'analytics_test' does not exist
#   /usr/local/bundle/gems/cassandra-driver-3.2.2/lib/cassandra/future.rb:637:in `get'
No examples found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions