RoR错误,我的Gemfile或测试配置问题

时间:2017-01-03 13:27:30

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems

我完全清楚我之前曾问过类似的问题,但这次我有更详细的情况。

似乎我无法测试我的应用程序,因为我的Gemfile或测试配置有问题。

显然这也称为RoR错误。

我正在使用cloud9开发环境,我的工作区正在运行ruby 2.3.0p0(2015-12-25 revision 53290)[x86_64-linux]。

以下是我的Gemfile:

source 'https://rubygems.org'

gem 'devise'

gem 'bootstrap-sass'
#modernizr
gem 'modernizr-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

gem 'haml-rails'

当我运行rake test时,我收到以下错误:

> [NOTE]
>
> You may have encountered a bug in the Ruby interpreter or extension libraries.
>
> Bug reports are welcome.
> For details: http://www.ruby-lang.org/bugreport.html
>
> Aborted

我的应用程序中有3个控制器,其中两个是模型。第三个控制器只是我用来处理主视图(主界面)而不是模型的控制器。

我将第3个模型生成为独立控制器,但其他两个控制器是我生成的支架的一部分。 (客户和项目)

这是我的客户控制器测试:

require 'test_helper'

class ClientsControllerTest < ActionController::TestCase
  setup do
    @client = clients(:one)
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:clients)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  test "should create client" do
    assert_difference('Client.count') do
      post :create, client: { name: @client.name, email: @client.email + "create" }
    end

    assert_redirected_to client_path(assigns(:client))
  end

  test "should show client" do
    get :show, id: @client
    assert_response :success
  end

  test "should get edit" do
    get :edit, id: @client
    assert_response :success
  end

  test "should update client" do
    patch :update, id: @client, client: { name: @client.name }
    assert_redirected_to client_path(assigns(:client))
  end

  test "should destroy client" do
    assert_difference('Client.count', -1) do
      delete :destroy, id: @client
    end

    assert_redirected_to clients_path
  end
end

项目控制器测试:

require 'test_helper'

class ProjectsControllerTest < ActionController::TestCase
  setup do
    @project = projects(:one)
    @client = clients(:one)
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:projects)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  test "should create project" do
    assert_difference('Project.count') do
      post :create, project: { client_id: @client, project_description: @project.project_description, project_timescale: @project.project_timescale, title: @project.title }
    end

    assert_redirected_to project_path(assigns(:project))
  end

  test "should show project" do
    get :show, id: @project
    assert_response :success
  end

  test "should get edit" do
    get :edit, id: @project
    assert_response :success
  end

  test "should update project" do
    patch :update, id: @project, project: { client_id: @project.client_id, project_description: @project.project_description, project_timescale: @project.project_timescale }
    assert_redirected_to project_path(assigns(:project))
  end

  test "should destroy project" do
    assert_difference('Project.count', -1) do
      delete :destroy, id: @project
    end

    assert_redirected_to projects_path
  end
end

指数控制器测试:

require 'test_helper'

class IndexControllerTest < ActionController::TestCase
  test "should get index" do
    get :index
    assert_response :success
  end

  test "should get contact"  do 
    get :contact 
    assert_response:success

    assert_template layout: 'application'

    assert_select'title', 'My Notes'
    assert_select'h1', 'Contact Us' 
    assert_select 'p', 'Complete the following form to get in touch with us.' 
    end

end

客户端模型测试:

require 'test_helper'

class ClientTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end

  #tests to see if an empty client can be created
  test "no empty clients!" do
    client = Client.new
    client.save

    refute client.valid?
  end

  #checks if a valid client can be created
  test "should save valid clients" do
    client = Client.new

    client.name = "David"
    client.email = "example@gmail.com"

    client.save
    assert client.valid?
  end

  test "no duplicate emails" do

    client1 = Client.new
    client1.name = "David"
    client1.email = "example@gmail.com"
    client1.save
    assert client.valid?

    client2 = Client.new
    client2.name = "David"
    client2.email = "example@gmail.com"
    client2.save
    refute client.valid?
  end

end

项目模型测试:

require 'test_helper'

class ProjectTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end

  setup do
    @client = clients(:one)
  end

  test "no empty projects" do 
    project = Project.new
    project.save

    refute project.valid?
  end


  test "make valid projects" do
    project = Project.new

    project.title = "first project"
    project.project_description = "building a forum for a game clan"
    project.project_timescale = "1 month"

    project.save
    assert project.valid?
  end
end

clients.yml:

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
  name: MyString
  email: MyText1

two:
  name: MyString
  email: MyText2

projects.yml:

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
  client: one
  project_description: MyText
  project_timescale: MyString
  title: MyString

two:
  client: two
  project_description: MyText
  project_timescale: MyString
  title: MyString

0 个答案:

没有答案