Created
November 7, 2012 07:12
-
-
Save xirukitepe/4029959 to your computer and use it in GitHub Desktop.
Example usage of Fixture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To see the fixtures applied in a practical example, suppose we want to test a chat's application that displays some messages. For this #functionality we write the following spec: | |
#spec/views/chats/show.html.erb_spec.rb | |
describe "views/chats/show.html.erb" do | |
fixture :chats, :messages | |
before(:each) do | |
@chat = chats(:myChat) | |
render "/chats/show.html.erb" | |
end | |
it "should render attributes in paragraph" do | |
response.should have_text(/MyString/) | |
end | |
it "should render all messages for the chat" do | |
response.should have_tag("tr>td", "Hello!", 1) | |
response.should have_tag("tr>td", "How are you?", 1) | |
response.should have_tag("tr>td", "Excellent!", 1) | |
end | |
end | |
#With these fixtures: | |
#spec/fixtures/chats.yaml | |
myChat: | |
name: MyString | |
id: 1 | |
#spec/fixtures/messages.yaml | |
one: | |
data: Hello | |
chat_id: 1 | |
version: 1 | |
user_id: 1 | |
two: | |
data: How are you? | |
chat_id: 1 | |
version: 2 | |
user_id: 1 | |
three: | |
data: Excellent! | |
chat_id: 1 | |
version: 3 | |
user_id: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment