我在RSpec的測試並不能弄清楚爲什麼我不斷收到此錯誤信息:RSpec的失敗,顯示消息
→ rspec
.F.F.[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. ...
Failures:
1) An event is not free if the price is positive
Failure/Error: expect(event).not_to be_free
expected free? to return false, got true
# ./spec/models/event_spec.rb:13:in `block (2 levels) in <top (required)>'
2) Viewing an individual event shows the price for an event with a non-zero price Failure/Error: expect(page).to have_text("$10.00") expected to find text "$10.00" in "BugSmash A fun evening of bug smashing! When 2014->01-16 15:42:35 UTC Where Denver Price Free All Events" # ./spec/features/show_event_spec.rb:21:in `block (2 levels) in '
Finished in 0.39876 seconds
8 examples, 2 failures
Failed examples:
rspec ./spec/models/event_spec.rb:10 # An event is not free if the price is positive
rspec ./spec/features/show_event_spec.rb:16 # Viewing an individual event shows the price for an event with a non-zero price
Randomized with seed 37892
這裏是event_spec .rb:
require 'spec_helper'
describe "An event" do
it "is free if the price is $0" do
event = Event.new(price: 0)
expect(event).to be_free
end
it "is not free if the price is positive" do
event = Event.new(price: 10)
expect(event).not_to be_free
end
end
這裏是我show_event_spec.rb:
require 'spec_helper'
describe "Viewing an individual event" do
it "shows the event's details" do
event = Event.create(event_attributes)
visit event_path(event)
expect(page).to have_text(event.name)
expect(page).to have_text(event.location)
expect(page).to have_text(event.description)
expect(page).to have_text(event.start_at)
end
it "shows the price for an event with a non-zero price" do
event = Event.create(event_attributes(price: 10.00))
visit event_path(event)
expect(page).to have_text("$10.00")
end
it "shows 'Free' for an event with a zero price" do
event = Event.create(event_attributes(price: 0.00))
visit event_path(event)
expect(page).to have_text("Free")
end
end
這裏是event.rb:
class Event < ActiveRecord::Base
def free?
price.blank? || price.zero?
end
end
index.html.erb:
<h1><%= pluralize(@events.size, 'Event') %></h1>
<% @events.each do |event| %>
<article>
<header>
<h2><%= link_to event.name, event %></h2>
</header>
<p>
<%= truncate(event.description, length: 35, separator: ' ') %>
</p>
<table>
<tr>
<th>When:</th>
<td><%= event.start_at %></td>
</tr>
<tr>
<th>Where:</th>
<td><%= event.location %></td>
</tr>
<tr>
<th>Price:</th>
<td><%= number_to_currency(event.price) %></td>
</tr>
</table>
</article>
<% end %>
和show.html.erb:
<article>
<header>
<h1><%= @event.name %></h1>
</header>
<p>
<%= @event.description %>
</p>
<h3>When</h3>
<p>
<%= @event.start_at %>
</p>
<h3>Where</h3>
<p>
<%= @event.location %>
</p>
<h3>Price</h3>
<p>
<%= format_price(@event) %>
</p>
</article>
<%= link_to "All Events", events_path %>
向我們展示您的型號代碼 – Agis
發佈。謝謝。 – Waymond