Tag: rspec

在创build新的Rails应用程序时,如何告诉Rails使用RSpec而不是testing单元?

我安装了test-unit并安装了rspec (以及-core , -expectations , -mocks和-rails版本2.6.x)。 当我运行命令rails new foo ,它使用test-unit来生成testing存根文件而不是rspec 。 有没有一个选项,我可以告诉rails使用rspec来生成testing呢?

我怎样才能检查一个表单域使用水豚正确预填?

我有一个适当的标签,我可以用水豚填写没有问题的领域: fill_in 'Your name', with: 'John' 我想在填写之前检查它的价值,并不能弄清楚。 如果我在fill_in之后添加以下行: find_field('Your name').should have_content('John') 该testing失败,虽然之前填写工作,因为我通过保存页面validation。 我错过了什么?

所有Rubytesting提升:nil:NilClass的未定义方法`authenticate'

我的大多数testing都提出以下,我不明白为什么。 所有的方法调用都会引发“validation”错误。 我已经检查了代码是否有一个称为“authentication”的方法,但没有这样的方法。 1) Admin::CommentsController handling GET to index is successful Failure/Error: get :index undefined method `authenticate!' for nil:NilClass # ./spec/controllers/admin/comments_controller_spec.rb:9:in `block (3 levels) in <top (required)>' 124) PostsController handling GET for a single post should render show template Failure/Error: get :show, :year => '2008', :month => '01', :day => '01', :slug => 'a-post' undefined […]

如何使用Capybara查询string获取当前path

这个页面的URL类似于/people?search=name而我使用的是水豚的current_path方法,它只返回/people 。 current_path.should == people_path(:search => 'name') 但它没有说 expected: "/people?search=name" got: "/people" 我们如何能通过? 有没有办法做到这一点?

如何使用RSpec检查JSON响应?

我在我的控制器中有以下代码: format.json { render :json => { :flashcard => @flashcard, :lesson => @lesson, :success => true } 在我的RSpec控制器testing中,我想validation某个场景是否收到成功的json响应,所以我有以下行: controller.should_receive(:render).with(hash_including(:success => true)) 虽然当我运行我的testing时,我得到以下错误: Failure/Error: controller.should_receive(:render).with(hash_including(:success => false)) (#<AnnoController:0x00000002de0560>).render(hash_including(:success=>false)) expected: 1 time received: 0 times 我是否检查错误?

没有主机链接到! 请提供:host参数或设置default_url_options

我现在一直在search90分钟左右,但仍然没有答案。 我在哪里设置default_url_options ? 我已经将它设置为config.action_mailer.default_url_options来解决这个相同的错误,但现在我得到这个错误,当试图在RSpec规范中使用URL助手。 我不知道在哪里期待default_url_options被设置。 Failure/Error: listing_url(listing).should match(/\/\d+-\w+$/) RuntimeError: Missing host to link to! Please provide :host parameter or set default_url_options[:host] # ./spec/routing/listing_routing_spec.rb:9:in `block (3 levels) in <top (required)>' 这个代码与电子邮件/ ActionMailer无关,只需要一个URL而不是一个path。 有任何想法吗?

设置RSpec来testing一个gem(不是Rails)

使用rspec-rails的添加生成器来设置RSpec来testingRails应用程序非常简单。 但是如何添加RSpec来testing开发中的gem? 我不使用珠宝商或这样的工具。 我只是使用Bundler( bundle gem my_gem )来设置新gem的结构并手动编辑* .gemspec。 我还添加了s.add_development_dependency "rspec", ">= 2.0.0" gemspec并做了一个bundle install 。 有没有一些好的教程接下来做什么RSpec工作?

如何全局configurationRSpec以保持打开“–color”和“–format specdoc”选项

如何在Ubuntu中设置RSpec的全局configuration。 具体地说,所有我的项目(即每次在任何地方运行rspec)都会打开–color和–format specdoc。

Rspec:“array.should == another_array”,但没有关心顺序

我经常想要比较数组,并确保它们以任何顺序包含相同的元素。 在RSpec中有一个简洁的方法吗? 以下是不可接受的方法: #to_set 例如: array.to_set.should == another_array.to_set 当数组包含重复的项目时失败。 #sort 例如: array.sort.should == another_array.sort 当数组元素不执行#<=>时失败

如何使用RSpec的should_raise与任何exception?

我想要做这样的事情: some_method.should_raise <any kind of exception, I don't care> 我应该怎么做? some_method.should_raise exception …不起作用。