ruby post_spec.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby post_spec.rb相关的知识,希望对你有一定的参考价值。

# factories/users.rb

FactoryGirl.define do
  sequence :email do |n|
    "user#{n}@test.com"
  end

  factory :user do
    first_name 'Jon'
    last_name 'Snow'
    email { generate :email }
    password 'testing'
    password_confirmation 'testing'
  end

  factory :admin_user, class: "AdminUser" do
    first_name 'Admin'
    last_name 'User'
    email { generate :email }
    password 'testing'
    password_confirmation 'testing'
  end
end
Failures:

  1) Navigate index has a list of Posts
     Failure/Error: expect(page).to have_content(/Some|super/)
       expected to find text matching /Some|super/ in "Home Time Entries Account Log In Edit Profile Logout Posts # Date User Rationale"
     # ./spec/features/post_spec.rb:26:in `block (3 levels) in <top (required)>'
# factories/posts.rb

FactoryGirl.define do
  factory :post do
    date Date.today
    rationale 'Some Rationale'
    user
  end

  factory :second_post, class: "Post" do
    date Date.yesterday
    rationale 'super Potatoes'
    user
  end
end
# features/post_spec.rb

require 'rails_helper'

describe 'Navigate' do
  before do
    @user = FactoryGirl.create(:user)
    login_as(@user, :scope => :user)
  end

  describe 'index' do
    before do
      visit posts_path
    end

    it 'can be reached successfully' do
      expect(page.status_code).to eq(200)
    end

    it 'has a title of Posts' do
      expect(page).to have_content(/Posts/)
    end

    it 'has a list of Posts' do
      post1 = FactoryGirl.build_stubbed(:post)
      post2 = FactoryGirl.build_stubbed(:second_post)
      visit posts_path
      expect(page).to have_content(/Some|super/)
    end
  end

  describe 'Creation' do
    before do
      visit new_post_path
    end

    it 'has a form that can be reached at posts/new' do
      expect(page.status_code).to eq(200)
    end

    it 'can be created from new form page' do
      fill_in 'post[date]', with: Date.today
      fill_in 'post[rationale]', with: 'Some Rationale'
      click_on 'Save'

      expect(page).to have_content('Some Rationale')
    end

    it 'will have a user associated to it' do
      fill_in 'post[date]', with: Date.today
      fill_in 'post[rationale]', with: 'User_Association'
      click_on 'Save'

      expect(User.last.posts.last.rationale).to eq('User_Association')
    end
  end
end

以上是关于ruby post_spec.rb的主要内容,如果未能解决你的问题,请参考以下文章

Ruby运算符

Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速

如何学习ruby?Ruby学习技巧分享

ruby Ruby脚本,看看是否用openssl编译了ruby

什么是ruby?

ruby和ruby ee