Example if the view has a form with few fields and a submit button, I want to test whether the data that i enter is according to the database,i.e the model(Having all validations[Null]) and the page gets redirected to success page.
For Example:
require ‘spec_helper’
describe “/admin/books/new.html.erb” do
include Admin::BooksHelper
before(:each) do
assigns[:book] = stub_model(Book,
:new_record? => true,
:sku_number => “value for sku_number”,
:title => “value for title”,
:author1 => “value for author1”,
:author2 => “value for author2”,
:author3 => “value for author3”,
:author4 => “value for author4”,
:author5 => “value for author5”
Now, i am testing whether the form renders to new book form. Similarly for each input box, i want to test my data with different values and also test whether the form has been rendered to show page after submitting this new form.
I would be thankful to you if you can guide me on this.
Example if the view has a form with few fields and a submit button, I
want
to test whether the data that i enter is according to the database,i.e
the
model(Having all validations[Null]) and the page gets redirected to
success
page.
Views are dumb. What you want to test is actually controller
functionality. And although you can do it with just RSpec, I'd
recommend using Cucumber for anything at the feature or acceptance
level.
In order to test my views, I have written few specs as given in the
examples.
Is there any way to test the user acceptance?
i.e suppose the field takes a string.
I want to test it for integers, float values, alphanumeric values, etc
and
run tests against that.
These sound like unit tests for the model to me. As mentioned views are
dumb (unless you're talking about client-side JavaScript validation).
What you really care about is whether invalid data can make it through
your model validation.
I need to get the tests failed as it takes only string.
I would be really thankful if someone can guide me on this.
The kinds of things you want to test in your view specs is whether the
text field gets rendered, that it's the right kind of control, has the
right style class or id applied to it, that it has the right label, etc.
If you want to create specs for user acceptance then integration specs
are the place to do that. As also mentioned; Cucumber provides a great
way to provide those integration specs. Cucumber makes the acceptance
test easy for the stakeholder to read and understand, which is vital to
good user acceptance scripts.