Tag: rspec

模块内部控制器的规范(版本主义者)

我正在Rails中创建一个API,我使用versionist来处理版本。 我想测试API控制器,但我无法创建有效的请求。 我的控制器: class Api::V1::ItemsController < Api::V1::BaseController def index render json:'anything' end end 我的规格: describe Api::V1::ItemsController do describe “#create” do it “shows items” do get :index, format: :json end end end routes.rb中: scope ‘/api’ do api_version(:module => “Api::V1”, :path => {:value => “v1”}, :default => true) do resources :items end end 测试没有检查任何东西。 但是,它引发了一个错误: Failure/Error: get […]

自定义ActiveModel full_messages

我想从我的自定义validation消息中删除该属性,只显示消息,而不是 School Please Provide Your School Name 我想回来 Please Provide Your School Name 正如我的模型中所设定的那样 validates :school, presence: { message: ‘Please Provide Your School Name’ } 消息作为JSON响应返回。 查看full_messages方法 # File activemodel/lib/active_model/errors.rb, line 348 def full_messages map { |attribute, message| full_message(attribute, message) } end 我可以用这个覆盖它 # File activemodel/lib/active_model/errors.rb, line 348 def full_messages map { |attribute, message| full_message(message) […]

在Selenium 2.9中选择Image

我正在尝试使用RSpec来尝试自动化测试维护后的周末,我正在这里实习。 我正在使用Selenium WebDriver 2.9.0获取一个特定的代码,然后添加个性化代码。 我目前所坚持的是尝试让WebDriver点击一个图像,然后导航到正确的HTML,但我目前无法这样做。 这是我到目前为止所拥有的…… it “can go to Ultratime” do @ie_driver.find_element(:link, “My Resources”).click wait.until { @ie_driver.execute_script(“return document.readyState;”) == “complete” } sleep 3 wait.until { @ie_driver.find_element(:link_text => “Login”).displayed?} #test above line puts “found Ultratime” #this just finds the “Logout” button and clicks it @ie_driver.find_element(:name, “ee”).click end 这是与我试图浏览的网站的“按钮”相关的HTML代码: Login 任何帮助将不胜感激!

如何使用rspec更改属性值

我是rspec的新手,我遇到了一些问题。 有人能帮帮我吗? 我有一个控制器动作负责停用用户。 我试图用rspec测试覆盖它,但结果不是我在等待的。 控制器: def deactivate @user = User.find(params[:id]) if !@user.nil? @user.update_attribute(:active, false) redirect_to users_url end end 控制器规格 describe “PUT #deactivate” do describe “with valid parameters” do before (:each) do @user = mock_model(User, :id => 100, :login => “login”, :password => “password123”, :email => “email@gmail.com”, :active => true) User.should_receive(:find).with(“100”).and_return(@user) end it “should deactivate an […]

RSpec:ActionView :: Template :: Error:nil的未定义方法`full_name’:NilClass

启动规范测试时,我收到此错误。 我知道没有设置与用户的连接。 我该怎么办才能通过考试? RSpec文件:posts_controller_spec.rb require ‘spec_helper’ include Devise::TestHelpers describe PostsController do render_views context “Logged in as user” do let(:user) { FactoryGirl.create(:user) } before { login_as(user) } context “on viewing index page” do let!(:p) { FactoryGirl.create(:post) } before { get :index } it { should respond_with(:success) } it { assigns(:posts).should == [p] } end end end […]

以编程方式测试任意用户是否可以访问任意文件

我希望能够编写说明用户soandso可以读取或编辑文件such_and_such测试或规范。 虽然我最终希望这是在RSpec中,但我认为它将全部归结为Bash命令(当然,整齐地包装在Ruby方法中),因为它似乎在Ruby的File类中不可用,或者我看过的其他任何事情。 我一直在寻找Bash中的东西来做这件事,并且找不到任何东西(File类中的任何东西看起来都没用)。 (注意:File.owned? 不能做我想要的,因为它只测试运行Ruby代码的进程是否为所有者,而不是任何任意用户有权编辑或读取,因此它在两个方面有显着差异。) 有没有办法做到这一点,内置到Bash? (或Ruby,或者一些我错过的Ruby gem?)或者我是否需要自己构建一个系统,获取文件的所有者和组信息,以及每个的读取,写入和执行位,然后查找该组的成员(如果so_and_so不是所有者),并通过所有权或组成员身份查看所需的权限是否可用于soandso ? 我目前只关心在类Unix系统上这样做,虽然不依赖于也可以在Windows上运行的Unix shell,这将是一个很好的奖励。 另外,我对测试实际文件感兴趣,所以像FakeFS这样的东西(据我所知)对我没用。 我不是要测试我的Ruby代码如何与文件系统交互,我试图validation是否可以对实际文件和目录执行所有必要的操作。 (同样,)我希望能够指定soandso可以编辑(或读取)文件such_and_such ,而不是指定文件such_and_such由soandso拥有。 这一点的重点不是指定所有权(因为这是一个实现细节,可能需要更改以适应其他要求,例如安全性),但只指定我的应用程序和用户实际需要能够对文件系统执行的操作。

为什么我得到FactoryGirl错误的参数数量错误?

FactoryGirl在非rails应用程序中有奇怪的行为。 错误的参数数量错误…不知道为什么。 gideon@thefonso ~/Sites/testing (master)$ rspec spec /Users/gideon/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:6:in `define’: wrong number of arguments (1 for 0) (ArgumentError) from /Users/gideon/Sites/testing/spec/factories.rb:1:in `’ 以下是涉及的文件…… login_user_spec.rb require_relative ‘../spec_helper’ require_relative ‘../lib/login_user’ describe “Existing User Log in Scenario”, :type => :request do before :all do @user = FactoryGirl(:user) end xit “should allow user to select login from top nav” do visit […]

Rspec重构模型问题(来自rails测试处方4)

我正在通过rails 4处方,我有一个重构问题。 我正在创建一个项目管理应用程序,我正在构建以学习TDD。我遇到的问题是特定的测试中断,我无法弄清楚它为什么会这样。 这是现在可以使用的任务模型,但是当我将其切换到下面的新任务时会中断: class Task attr_accessor :size, :completed_at def initialize(options = {}) @completed = options[:completed] @size = options[:size] end def mark_completed @completed = true end def complete? @completed end end 这是项目模型: class Project attr_accessor :tasks def initialize @tasks = [] end def incomplete_tasks tasks.reject(&:complete?) end def done? incomplete_tasks.empty? end def total_size tasks.sum(&:size) end def […]

Rails – ruby​​ / 2.1.0 / minitest / parallel_each.rb:67:in”:类’Minitest :: Unit’的未定义方法’_run_suites’(NameError)

我克隆了这个存储库: https : //github.com/railstutorial/sample_app_rails_4 我按照说明在我的本地机器中设置项目: cd /tmp git clone https://github.com/railstutorial/sample_app_rails_4.git cd sample_app_rails_4 cp config/database.yml.example config/database.yml bundle install –without production bundle exec rake db:migrate bundle exec rake db:test:prepare bundle exec rspec spec/ 但是当我运行“bundle exec rspec spec”进行测试时,我得到了这个输出: No DRb server is running. Running in local process instead … /usr/lib/ruby/2.1.0/minitest/parallel_each.rb:67:in `’: undefined method `_run_suites’ for class `Minitest::Unit’ (NameError) […]

如何运行一次capybara命令,然后运行一些测试

我有给定的测试代码: describe ‘A new user’, js: true do before do @new_user = Fabricate.build(:user) end it ‘should sign up’ do #login code visit ‘/’ click_link ‘Login’ fill_in ‘user[email]’, :with => @new_user.email fill_in ‘user[password]’, :with => @new_user.password click_button ‘Login now’ #login code end page.should have_content(“Hello #{@new_user.first_name}!”) current_path.should == dashboard_path end it ‘should receive a confirmation mail’ do […]