rspec核心Ruby on Rails

乔瓦兹

您好,我正在用rspec测试我的应用程序:

这是测试文件。

require 'spec_helper'

describe RecipesController do
    render_views
    describe "index" do
        before do
            Recipe.create!(name: "Spaghetti alla Carbonara")
            Recipe.create!(name: "Spaghetti alle vongole e cozze")
            Recipe.create!(name: "Bistecca")
            Recipe.create!(name: "Fritto")

            xhr :get, :index, format: :json, keywords: keywords
        end

        subject(:results) { JSON.parse(response.body) }

        def extract_name 
            ->(object){ object["name"] } 
        end

        context 'quando la ricerca riporta dei risultati' do
            let(:keywords) { 'Spaghetti' }
            it 'essere 200' do
                expect(response.status).to eq(200)
            end

            it 'deve ritornare due risultati' do
                expect(results.size).to eq(2)
            end

            it 'deve esserci la ricetta Spaghetti alla Carbonara' do
                expect(results.map(&extract_name)).to include('Spaghetti alla Carbonara')
            end

            it 'deve esserci la ricetta Spaghetti alle vongole e cozze ' do
                expect(results.map(&extract_name)).to include('Spaghetti alle vongole e cozze')
            end
        end

        context 'quando la ricerca non riporta alcun risulato' do
            let(:keywords) { 'tortellini' }
            it 'non deve ritornare alcun risulato' do
                expect(results.size).to eq(0)
            end
        end


    end
end

当我尝试通过命令启动测试时:

耙db:migrate RAILS_ENV = test; rspec规范/控制器/recipes_controller_spec.rb

我收到这个错误

/var/lib/gems/2.1.0/gems/bundler-1.10.1/lib/bundler/runtime.rb:34:将block in setup': You have already activated rspec-core 3.3.1, but your Gemfile requires rspec-core 2.99.2. Prependingexec捆绑到您的命令中可以解决此问题。(Gem :: LoadError)

如日志中所述,该错误与rspec-core v3.3.1有一些冲突,因此在我的gem文件中,我添加了以下行以安装rspec-core v2.99.2

gem 'rspec-core', '~> 2.99.2'

但是,如果我再次启动该命令(在安装捆绑软件之后并使用捆绑软件exec),结果是相同的。有人有类似的问题吗?

马里奥腐肉

你试过了吗?

bundle exec rake db:migrate RAILS_ENV=test
bundle exec rspec spec/controllers/recipes_controller_spec.rb

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Ruby on Rails Rspec 验证

来自分类Dev

Rspec Rails单元测试-Ruby on Rails

来自分类Dev

Ruby on Rails-随机失败的RSpec测试

来自分类Dev

Ruby On Rails Rspec需要冲突

来自分类Dev

Rspec对象比较失败(Ruby on Rails)

来自分类Dev

无法覆盖Rails 2.3.4中的核心ruby类

来自分类Dev

需要与核心Ruby文件同名的Rails lib文件

来自分类Dev

RSpec的未定义方法“它”(Hartl的Ruby on Rails教程)

来自分类Dev

Ruby on Rails Rspec NoMethodError:未定义的方法“ not_to”

来自分类Dev

Rspec 测试在 Circle CI(Ruby on Rails 5.2.3)上失败

来自分类Dev

Ruby on Rails

来自分类Dev

Ruby on Rails-无法运行以下命令:rails generate rspec:install

来自分类Dev

优化Rails RSpec测试

来自分类Dev

Rspec Rails错误

来自分类Dev

使用Zeitwerk的Rails 6:如何扩展Ruby核心类,例如日期,时间,字符串等

来自分类Dev

在RSpec测试(Ruby on Rails)的上下文中,“ StringIO”是什么?

来自分类Dev

Ruby on Rails + Rspec:包含实例变量的 css 选择器的语法

来自分类Dev

Ruby on Rails rspec控制器测试失败,但不应该

来自分类Dev

RSPEC错误:预期:[2015-05-01 19:56:25 -0700]得到:零(与==相比)Ruby on Rails

来自分类Dev

Ruby on Rails:测试成功的HTTP状态时,Rspec路由错误

来自分类Dev

如何针对Ruby on Rails RSpec测试在`spec / support /`中使用模块

来自分类Dev

Rails rspec 功能测试使用“stripe-ruby-mock” gem 失败

来自分类Dev

测试应该在 Ruby on Rails 应用程序中使用 Rspec 测试什么

来自分类Dev

Rails RSpec意外警报打开

来自分类Dev

预期的Rails RSpec不是JSON

来自分类Dev

Rspec Rails打印很多警告

来自分类Dev

赋值返回nil rspec rails

来自分类Dev

Rails 5 Rspec ActionController :: UrlGenerationError

来自分类Dev

Rails-Rspec-存根参数

Related 相关文章

  1. 1

    Ruby on Rails Rspec 验证

  2. 2

    Rspec Rails单元测试-Ruby on Rails

  3. 3

    Ruby on Rails-随机失败的RSpec测试

  4. 4

    Ruby On Rails Rspec需要冲突

  5. 5

    Rspec对象比较失败(Ruby on Rails)

  6. 6

    无法覆盖Rails 2.3.4中的核心ruby类

  7. 7

    需要与核心Ruby文件同名的Rails lib文件

  8. 8

    RSpec的未定义方法“它”(Hartl的Ruby on Rails教程)

  9. 9

    Ruby on Rails Rspec NoMethodError:未定义的方法“ not_to”

  10. 10

    Rspec 测试在 Circle CI(Ruby on Rails 5.2.3)上失败

  11. 11

    Ruby on Rails

  12. 12

    Ruby on Rails-无法运行以下命令:rails generate rspec:install

  13. 13

    优化Rails RSpec测试

  14. 14

    Rspec Rails错误

  15. 15

    使用Zeitwerk的Rails 6:如何扩展Ruby核心类,例如日期,时间,字符串等

  16. 16

    在RSpec测试(Ruby on Rails)的上下文中,“ StringIO”是什么?

  17. 17

    Ruby on Rails + Rspec:包含实例变量的 css 选择器的语法

  18. 18

    Ruby on Rails rspec控制器测试失败,但不应该

  19. 19

    RSPEC错误:预期:[2015-05-01 19:56:25 -0700]得到:零(与==相比)Ruby on Rails

  20. 20

    Ruby on Rails:测试成功的HTTP状态时,Rspec路由错误

  21. 21

    如何针对Ruby on Rails RSpec测试在`spec / support /`中使用模块

  22. 22

    Rails rspec 功能测试使用“stripe-ruby-mock” gem 失败

  23. 23

    测试应该在 Ruby on Rails 应用程序中使用 Rspec 测试什么

  24. 24

    Rails RSpec意外警报打开

  25. 25

    预期的Rails RSpec不是JSON

  26. 26

    Rspec Rails打印很多警告

  27. 27

    赋值返回nil rspec rails

  28. 28

    Rails 5 Rspec ActionController :: UrlGenerationError

  29. 29

    Rails-Rspec-存根参数

热门标签

归档