ruby on rails - Mintest Rails4: ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "name" violates not-null constraint -
i'm trying test rails 4 application minitest. i've seed data, app setup. once seed data loaded in test database, try run test.
test_seed.rake
namespace :db namespace :test desc "load seed data before running tests" task :prepare => :environment puts "\nloading seed data.....\n\n" rake::task["db:seed"].invoke puts "\n....seed data loaded!\n\n" end end end having done that,
rake db:test:prepare then when put 'rake' command(as of not have testcase written)
test_helper.rb
env["rails_env"] = "test" require file.expand_path("../../config/environment", __file__) require "rails/test_help" require "minitest/rails" # add capybara feature tests add `gem "minitest-rails-capybara"` # test group in gemfile , uncomment following: require "minitest/rails/capybara" # uncomment awesome colorful output require "minitest/pride" # code coverage, refer https://github.com/colszowka/simplecov require 'simplecov' simplecov.start # create customizable minitest output formats require "minitest/reporters" minitest::reporters.use!( minitest::reporters::specreporter.new, env, minitest.backtrace_filter ) class activesupport::testcase activerecord::migration.check_pending! include factorygirl::syntax::methods # setup fixtures in test/fixtures/*.(yml|csv) tests in alphabetical order. # # note: you'll still have declare fixtures explicitly in integration tests # -- not yet inherit setting fixtures :all # add more helper methods used tests here... extend minitest::spec::dsl end class actiondispatch::integrationtest extend minitest::spec::dsl include capybara::dsl end gemfile:
group :test # minitest gem 'minitest-spec-rails', '5.2.0' gem 'minitest-rails-capybara', '2.1.1' gem 'minitest-reporters', '1.0.5' gem 'guard-minitest', '2.3.1' gem 'launchy' gem 'factory_girl_rails', "~> 4.2.1" gem 'faker', '1.4.3' gem 'simplecov', '0.9.2', require: false end existing test, role_test.rb:
require 'test_helper' class roletest < activesupport::testcase test "nothing" assert true # role_names = role.where(name: 'superadmin').collect(&:name) # assert_includes role_names, 'superadmin', 'it should include role superadmin' end it fails following error:
roletest test_0001_nothing error (0.02s) activerecord::statementinvalid: activerecord::statementinvalid: pg::notnullviolation: error: null value in column "name" violates not-null constraint detail: failing row contains (980190962, null, 2015-03-31 19:51:59, 2015-03-31 19:51:59, null, null, null, null, null, null, null). : insert "companies" ("created_at", "updated_at", "id") values ('2015-03-31 19:51:59', '2015-03-31 19:51:59', 980190962) fabulous run in 0.05302s 1 tests, 0 assertions, 0 failures, 1 errors, 0 skips can me on this, why @ i'm getting error? , if possible, suggestion fix it.
thanks
Comments
Post a Comment