테스트 스위트를 작동하지 못합니다. 다른 구성을 혼합하고 일치 시키려고했습니다. 그러나 결과는이보기에서 모두 동일합니다. 테스트 간에는 아무 것도 정리되지 않거나 데이터베이스가 비어 있습니다.데이터베이스 삭제 또는 데이터베이스 없음
아무것도1) Authentication Sign in page as new user with valid information creates a user
Failure/Error: select group.name, from: 'user_group_id'
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching option "Group g"
를 청소하지
하거나, 빈 DB :
1) Authentication Sign in page as new user with valid information creates a user
Failure/Error: select group.name, from: 'user_group_id'
Capybara::ElementNotFound:
Unable to find option "Group g"
내가 함께하고 database_cleaner.I하지 않고 노력했습니다
나는 오류의 종류를 얻을 Spork없이 시도했습니다. 난 exemple를 들어, 다른 구성이 다른 소스를 형성 시도했다 :
https://github.com/bmabey/database_cleaner#rspec-example
그러나 나는 그것이 작동하는 방법을 알아낼 수 없습니다.
여기에 보석 버전의 Gemfile의 :
<%= form_for(@user, url: sessions_path) do |f| %>
<div class="field">
<%= f.label :group_id %><br />
<%= f.collection_select :group_id, Group.order('name asc').all, :id, :name, :prompt => "Choose your Group" %>
</div>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :phone %><br />
<%= f.text_field :phone %>
</div>
<div class="actions">
<%= f.submit 'Go !'%>
</div>
<% end %>
두 모델 : 여기
gem 'rails', '3.2.13'
gem 'sqlite3'
group :development, :test do
gem 'libnotify'
gem 'rb-inotify'
gem 'rspec-rails' (2.13.0)
gem 'guard-rspec' (2.5.1)
gem 'guard-spork' (1.5.0)
gem 'guard-livereload'
gem 'rack-livereload'
end
group :test do
gem 'capybara' (2.0.2)
gem 'launchy'
gem 'database_cleaner' (0.9.1)
gem 'factory_girl_rails'
end
뷰의
class Group < ActiveRecord::Base
has_many :users
attr_accessible :name, :phone, :active
end
class User < ActiveRecord::Base
belongs_to :group
attr_accessible :name, :phone, :group_id
validates_presence_of :name, :phone, :group
end
그리고 해당 사양
require 'spec_helper'
describe "Authentication" do
subject { page }
before { visit root_path }
describe "Sign in page" do
let(:submit) {'Go !'}
let(:session_new_content) { "Who's nearby"}
let(:session_show_content){ "session show"}
describe "as new user" do
describe "with valid information" do
group = Group.create(name: "Group g")
before do
select group.name, from: 'user_group_id'
fill_in 'Name', with: 'Samy'
fill_in 'Phone', with: '0642604568'
end
it "creates a user" do
expect{ click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
let(:user) { User.find_by_phone '0643614864'}
before do
click_button submit
end
it { should have_content session_show_content}
it { should have_content user.name}
end
end
end
end
end
여기에 어떤 제안을의 나의 spec_helper.rb
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.include Rails.application.routes.url_helpers
config.include Capybara::DSL
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
end
Spork.each_run do
FactoryGirl.reload
end
입니까?
감사의가있다. –
답변 해 주셔서 감사합니다. 진실은 이미 당신이 언급 한 두 가지 해결책을 모두 시도한 것입니다. 그리고 나는이 두 가지 오류 중 하나를 계속해서 지킵니다. –
다시 한번 감사드립니다. 그러나 나는 이미 이것을 시도했다. 문제의 출처를 파악할 수 없습니다. –