Tag: rspec

RubyTest与SublimeText 2

我正在使用Sublime Text 2并安装了RubyTest包。 我正在尝试使用Command-Shift-R运行测试。 我也使用rbenv作为ruby并使用Bundler安装了gem。 输出是: /bin/sh: rspec: command not found 控制台显示以下命令已运行: cd ‘/Users/user/Dropbox/code/app/’ && rspec spec/controllers/profile_controller_spec.rb -l 163 当我在终端中运行该命令时,它工作正常。 为什么它在Sublime中不起作用?

Ruby / Rails / Rspec – ActiveRecord :: AssociationTypeMismatch:

好的,这是我的rspec代码…… before(:each) do @attr = { :greeting => “Lorem ipsum”, :recipient => @recipient } end it “should redirect to the home page” do puts “spec: @attr = #{@attr}” puts “spec: recipient = #{@attr[:recipient]}” post :create, :card => @attr response.should redirect_to(root_path) end 现在这个输出是: spec: @attr = {:greeting=>”Lorem ipsum”, :recipient=>#} spec: recipient = # 所以我们可以看到收件人是用户。 在控制器方面,我们看到…… def […]

RSpec不加载我的类,即使它在Rails控制台中加载

我在app/models/parser有一个名为data.rb ,内容如下: class Parser::Data def method1 end end 在这一点上没什么好看的。 我试图在实现太多之前为它编写测试,只是为Rails做了默认的RSpec安装。 我的RSpec文件在spec/models/parser/data_spec.rb ,到目前为止非常基础: require ‘spec_helper.rb’ describe Parser::Data do let(:parser) { Parser::Data.new } end 当我运行测试时,我收到此错误: spec/models/parser/data_spec.rb:3:in `’: uninitialized constant Parser (NameError) 我尝试将module Parser放在Data类的同一目录app/models/parser ,我也尝试将它移动到lib/parser做同样的模块包装类,并在application.rb添加了lib/parser到autoload但是到目前为止没有任何工作。 我究竟做错了什么?

加载rubygems时出错

在需要加载rubygems(来自config / boot.rb文件)的操作(rspec相关)期间,我收到以下错误消息: ~/config/boot.rb:1:in `require’: no such file to load — rubygems (LoadError) ~/config/boot.rb:1 from ~/config/application.rb:1:in `require’ from ~/config/application.rb:1 from ~/config/environment.rb:2:in `require’ from ~/config/environment.rb:2 from ~/spec/spec_helper.rb:3:in `require’ from ~/spec/spec_helper.rb:3 from ~/spec/models/user_spec.rb:1:in `require’ from ~/spec/models/user_spec.rb:1 from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load’ from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load_files’ from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `each’ from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `load_files’ from /usr/lib/ruby/1.8/spec/runner/options.rb:132:in `run_examples’ from /usr/lib/ruby/1.8/spec/runner/command_line.rb:9:in `run’ from /usr/bin/spec:3 我在SO上查找了这个错误并发现了以下主题: […]

rails教程期望css标题与文本返回一些东西

我正在研究ruby.railstutorial.org上的RoR教程,目前正在第4章。测试没有validation,我不明白为什么。 我的spec文件的顶部部分看起来像这样。 其他方法看起来与帮助相同: describe “StaticPages” do let(:page_title) {“Ruby on Rails Tutorial Sample App”} let(:h1_test) {“should have the h1”} let(:title_test) {“should have the title”} describe “Home page” do |title_test, h1_test| it “#{h1_test} ‘Sample App'” do visit ‘/static_pages/home’ page.should have_selector(‘h1′,:text=>’Sample App’) end it “#{title_test} ‘Home'” do visit ‘/static_pages/home’ page.should have_selector(‘title’, :text=> ‘#{page_title}’) end it “should not have […]

RSpec – 无效的空格字符导致未定义的方法`should’?

在RubyMine和Atom中编写规范时,我偶尔会遇到一个非常烦人的错误,因为似乎存在无效的空格字符,因此ruby会将第一个(空白)字符作为方法名称的一部分进行评估。 1) Activity Failure/Error: it { should belong_to :micropost } NoMethodError: undefined method ` should’ for # # ./spec/models/activity_spec.rb:5:in `block (2 levels) in ‘ 请注意错误消息中’ should’前面的空格。 我试过打开隐形字符,我看不到任何与普通空间不同的东西。 删除it块内的第一个空格并点击空格键可以解决问题,但是回过头来修复块一直很烦人。 有关导致错误的原因的任何想法? 添加 通过建议,我添加了在hex编辑器中打开的规范。 有问题的字节是C2 A0 – it {¬†should belong_to :micropost } 69 74 20 7B C2 A0 73 68 6F 75 6C 64 20 62 65 6C […]

使用RSpec的请求规范测试外部API

我正在尝试使用RSpec的请求规范将主机更改为指向远程URL而不是localhost:3000。 如果可能,请告诉我。 注意:只是想提一下远程URL只是一个JSON API。

Rspec 3.未定义的局部变量或方法`response’for#

我想用rspec测试API控制器。 所以这是一段简单的代码: require ‘rails_helper’ describe “GET /api/config” do it ‘routes GET to /api/config to Api::V1::ConfigsController#show’ do get ‘/api/config.json’ expect(response).to be_success end end 但我有一个错误: 1) Configs API GET /api/config routes GET to /api/config to Api::V1::ConfigsController#show Failure/Error: expect(response).to be_success NameError: undefined local variable or method `response’ for # # ./spec/routing/api/v1/devise/configs_routing_spec.rb:13:in `block (3 levels) in ‘

使用带有Page-Object的IE 11 x64时出现“Watir :: Exception :: NoMatchingWindowFoundException:浏览器窗口已关闭”错误

我正在使用Page-Object + Rspec在Ruby Mine 2.7.1中运行测试。 环境:Windows 7 x64,Ruby 1.9.3 p551,IE 11。 Gems: watir , rspec , bundler , page-object 当我在Chrome或Firefox中运行测试时,一切正常。 但是当我尝试在IE中运行它们时,带有正确页面的IE窗口会被打开,之后我会在主题中指定错误: “Watir::Exception::NoMatchingWindowFoundException: browser window was closed” 关键是浏览器实际上是在那一刻打开并显示正确的页面。 (参见截屏video,了解会发生什么: http : //screencast.com/t/06prRy3OMLM ) 测试结束时出现错误,并且config.after do部分未执行,因为浏览器窗口仍然打开。 执行以下代码时会发生该错误: before(:each) do visit end 好像IEDriverServer在页面打开后立即失去与IE的连接。 最令人困惑的是,在极少数情况下,一切都运行良好,在更罕见的情况下,一切都在使用最终的超时错误显着减速。 sleep 延迟没有帮助。 我尝试了不同版本的selenium-webdriver gem(它是watir gem需要的),不同版本的IEDriverServer用于x86和x64平台 – 结果是一样的。 lib/watir-classic/exceptions.rbexception描述如下: # This exception is raised if […]

Capybara :: ElementNotFound:无法找到字段“title”

我无法解决这个问题。 请帮我。 它给了我找不到元素的错误。 规格/function/待办事项/ create_spec.rb require ‘spec_helper’ describe “Creating todos” do let(:user) { FactoryGirl.create(:user)} before(:each) do visit root_path click_link “Login” fill_in “Email”, with: “user@gmail.com” fill_in “Password”, with: “password” click_button “Sign in” end it “redirects to the todos index page” do visit “/todos” fill_in “title”, with: “MyString” click_button “Create” expect(page).to have_title(“MyString”) end 我的观点代码。 _new_form.html.erb spec_helper.rb def […]