Rspec - In views

Hi All,

I want to test my application with rspec.

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.

I need to get the tests failed as it takes only string.

I would be really thankful if someone can guide me on this.

Please help me with a simple example so that I can understand it quickly and move ahead.

Thanks in advance.

Hi

But you haven't given any example

Hi,

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”

) end

it “renders new book form” do render

response.should have_tag(“form[action=?][method=post]”, admin_books_path) do with_tag(“input#book_sku_number[name=?]”, “book[sku_number]”) with_tag(“input#book_title[name=?]”, “book[title]”) with_tag(“input#book_author1[name=?]”, “book[author1]”) with_tag(“input#book_author2[name=?]”, “book[author2]”) with_tag(“input#book_author3[name=?]”, “book[author3]”) with_tag(“input#book_author4[name=?]”, “book[author4]”) with_tag(“input#book_author5[name=?]”, “book[author5]”)

end end end

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.

Thanks!!

Rails ROR wrote:

Hi,

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.

Best,

Rails ROR wrote:

Hi All,

I want to test my application with rspec.

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.