spec / controllers / undertakes_controller_spec.rb :
describe 'undertake comment' do
let(:user) do
build(:user)
end
before do
user1=create(:user)
user1.id=1
login_as(user1)
@undertake=create(:undertake)
end
it 'can create comment' do
visit undertake_path(@undertake)
expect(current_path).to eq undertake_path(@undertake)
within("form#undertake-form-test") do
fill_in "content" , with: "heyheyhey"
end
click_button "Send"
expect(page).to have_content 'heyheyhey'
end
end
承担/ show.html.erb :
<%= form_for(@comment , url: undertake_comments_url(@undertake) , id: 'undertake-form-test') do |f| %>
<div class="field">
<%= f.label :content , class:"form-label" %><br />
<%= f.text_area :content, placeholder: '返信する' , class:'text-area-css' %>
</div>
<div class="actions">
<%= f.submit "Send" , class:' btn btn-primary btn-lg' %>
</div>
<% end %>
为什么我有错误Capybara::ElementNotFound:Unable to find button "Send"
。
请帮帮我。
答案 0 :(得分:0)
您应该像这样测试控制器
RSpec.describe UndertakesController, :type => :controller do
describe 'POST #create' do
before do
user1 = create(:user)
user1.id = 1
login_as(user1)
@undertake = build(:undertake)
end
post :create, :params => { :undertake => { @undertake } }
expect(Undertake.count).to eq(1)
end
end
仅举例说明如何进行创作。