Tag: rspec

spork 0.9.2和rspec 3.0.0 =未初始化的常量RSpec :: Core :: CommandLine(NameError)

我使用spork 0.9.2和rspec 3.0.0。 当试图运行测试rspec –drb我有一个例外 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in run_tests: uninitialized constant RSpec::Core::CommandLine (NameError) 但是当将rspec版本改回2.6时 – 一切都还可以。 有人遇到过同样的问题吗? 可以解决吗?

如何在irb中使用RSpec期望值

我想用[1,2,3].should include(1) 。在irb中[1,2,3].should include(1) 。 我试过了: ~$ irb 1.9.3p362 :001 > require ‘rspec/expectations’ => true 1.9.3p362 :002 > include RSpec::Matchers => Object 1.9.3p362 :003 > [1,2,3].should include(1) TypeError: wrong argument type Fixnum (expected Module) from (irb):3:in `include’ from (irb):3 from /home/andrey/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in `’ 但它不起作用虽然它是一个有效的案例 。 我如何使用[1,2,3].should include(1) ?

Rails 4 – 语法错误,意外的tIDENTIFIER,期望输入结束

我有一段代码,我试图用rspec运行。 require ‘spec_helper’ describe “User” do before { @user = User.new(name: “Example User”, email: “user@example.com”, password: “foobar”, password_confirmation: “foobar”) } subject { @user } it { should respond_to(:name)} end 我收到以下错误 c:\Sites\sample_app>rspec spec/models/user_spec.rb C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec /core/configuration.rb:819:in `load’: c:/Sites/sample_app/spec/models/user_spec. rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input (SyntaxError) before { @user…er’ 现在我在一个新文件中重新键入测试并运行它并且没有错误。 我想有一些编码问题或者我没有学到的东西,我没有得到。 有没有人可以对这个问题有所了解?

Rails:使用RSpec测试命名范围

我是测试Rails Web应用程序和RSpec的新手。 我使用遗留代码并需要添加测试。 那么使用RSpec测试查找器和命名范围的最佳方法是什么? 我在Google中找到了一些方法,但它们并不理想。 例如: http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in​​-ruby-on-rails it “excludes users that are not active” do @user = Factory(:user, :active => false) User.active.should_not include(@user) end 要么 http://h1labs.com/notebook/2008/8/21/testing-named-scope-with-rspec it “should have a published named scope that returns …” do Post.published.proxy_options.should == {:conditions => {:published => true}} end 我在“铁路测试处方”中找到最佳方法(恕我直言): should_match_find_method :active_only { :active == true } 其中should_match_find_method自定义帮助方法

rspec和shoulda – 补充还是替代?

我已经使用了一段时间了,我已经阅读并使用了rspec。 我还没有深入比较和对比。 但在我看来,两者之间存在一些重叠,但它们不是1-1的替代品。 我正在考虑使用rspec在我的rails系统中编写一些unit testing,而不是替换用shoulda编写的所有现有测试。 就像一种获得感觉的方式。 这是一个好主意吗? 我可以逐渐从一个移动到另一个,还是我在寻找麻烦? 我应该考虑一个明显的优势吗? 谢谢!

为什么RSpec的方法,“获取”,“发布”,“放置”,“删除”不在gem(或Rails外部)的控制器规范中工作?

我不是Rails或Rspec的新手,但我是制作gem的新手。 当我测试我的控制器时,REST方法“get”,“post”,“put”,“delete”给我一个未定义的方法错误。 您可以在下方找到代码,但如果您希望在贴图中看到它, 请单击此处 。 谢谢! 这是我的spec_helper: $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), ‘..’, ‘lib’)) require ‘rubygems’ require ‘active_support’ unless defined? ActiveSupport # Need this so that mattr_accessor will work in Subscriber module require ‘active_record/acts/subscribable’ require ‘active_record/acts/subscriber’ require ‘action_view’ require ‘action_controller’ # Since we’ll be testing subscriptions controller #require ‘action_controller/test_process’ require ‘spec’ require ‘spec/autorun’ # Need active_support to user […]

反对在RSpec测试中使用之前,之后和主题的论点是什么?

我刚刚开始编写RSpec测试,我遇到了thinkbot的Style Guide ,它建议不要let , let! , before和subject (以及其他)。 我也在其他几个地方读过类似的建议(包括旧的RSpec文档警告before(:all) ),但我似乎无法找到反对它们的实际论点。 所以问题是: 为什么我不应该在测试中使用这些方法? 什么是更好的方法?

RSpec的主题与let之间有什么区别? 什么时候应该使用它们?

http://betterspecs.org/#subject有一些关于subject和let 。 但是,我仍然不清楚它们之间的区别。 此外,SOpost反对在RSpec测试中使用之前,之后和主题的论点是什么? 说不要使用任何一个subject或let更好。 我该去哪儿? 我感到很困惑。

检查为什么ruby脚本挂起

有时我的规格可能会挂起,我必须杀死相应的ruby进程。 当我运行用capybara和webkit驱动程序编写的集成规范时,这很常见。 是否可以检查给定的ruby过程并查看它挂在哪里? 哪种方法,操作,文件,行号等

Mysql ::错误:指定的密钥太长; 最大密钥长度为767字节:CREATE INDEX

我正在使用rails 2.3.5应用程序,在女巫我有这个领域 t.string “trip_cities”, :limit => 256 而这个指数 add_index “bookings”, [“trip_cities”], :name => “trip_cities” 当我尝试执行时: bundle exec rake db:test:load 我收到此错误Mysql::Error: Specified key was too long; max key length is 767 bytes: CREATE INDEX ‘trip_cities’ ON ‘bookings’ (‘trip_cities’) Mysql::Error: Specified key was too long; max key length is 767 bytes: CREATE INDEX ‘trip_cities’ ON ‘bookings’ (‘trip_cities’)并且不太知道如何解决这个问题。