Display Rspec output in an html file

Hello,
I had written some model scenarios.
Now i want to generate that output in an html file.
i am executing the models using rake i.e. rake spec:models from spec
directory.
But the html file is not getting generated.

Following is the error trace:
** Invoke spec:models (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute spec:models
./spec/models/forum_spec.rb:43: warning: don’t put space before argument
parentheses
./spec/models/forum_spec.rb:50: warning: don’t put space before argument
parentheses
#<Forum id: 3, name: “Forum2”, description: “Desc”, topics_count: 0,
posts_count: 0, position: nil, description_html: “

Desc

”,
idiom_id: nil, permalink: “forum2”>
#<Poll id: nil, title: " “, published: false, channel_feature_id: nil,
created_at: nil, updated_at: nil>
rake aborted!
Command /usr/local/bin/ruby
-I”/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib"
“/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.4/bin/spec”
“spec/models/forum_spec.rb” “spec/models/attachment_spec.rb”
“spec/models/channel_detail_spec.rb” “spec/models/whatwewant_spec.rb”
“spec/models/channel_spec.rb” “spec/models/question_spec.rb”
“spec/models/rating_spec.rb” “spec/models/topic_spec.rb”
“spec/models/channel_feature_spec.rb” “spec/models/idea_spec.rb”
“spec/models/user_channel_spec.rb” “spec/models/promotion_spec.rb”
“spec/models/product_spec.rb” “spec/models/poll_spec.rb”
“spec/models/bb_post_spec.rb” “spec/models/channel_category_spec.rb”
“spec/models/survey_spec.rb” --format html:result.html failed
/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/rake/spectask.rb:174:in
define' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:inverbose’
/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/rake/spectask.rb:150:in
define' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain’
/usr/local/lib/ruby/1.8/monitor.rb:242:in synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in
top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun’
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/local/bin/rake:19:in `load’
/usr/local/bin/rake:19

I had tried various options:
1:Under lib/tasks/rspec file i had added a line
“t.spec_opts = [’–format’ , ‘html:result.html’ ]” under the

[:models, :controllers, :views, :helpers, :lib, :integration].each do
|sub|
desc “Run the code examples in spec/#{sub}”
Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
t.spec_opts = [’–options’, “”#{RAILS_ROOT}/spec/spec.opts""]
t.spec_files = FileList[“spec/#{sub}/**/*_spec.rb”]
t.spec_opts = [’–format’ , ‘html:result.html’ ]
end
end
but when i run the rake command above error is generated.

2:I also tried updating spec.opts file by adding --format
html:spec/a.html.
After adding this code i ran the spec using rake spec:models
RAILS_ENV=test but what i think that if we add something in spec.opts
then running command for models is different.

Please suggest how to display output in html using rake command rake
spec:models

My spec.opts file contains
–colour
–format html:spec/a.html
–loadby
mtime
–reverse

On 9 Nov 2009, at 11:13, Amit K. wrote:

** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment
idiom_id: nil, permalink: “forum2”>
“spec/models/channel_feature_spec.rb” “spec/models/idea_spec.rb”
spectask.rb:150:in
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
`top_level’
/usr/local/bin/rake:19
t.spec_files = FileList[“spec/#{sub}/**/*_spec.rb”]

Please suggest how to display output in html using rake command rake
spec:models

Posted via http://www.ruby-forum.com/.


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Do you get an error message? I don’t see one here.

cheers,
Matt

+447974 430184

Yes i get an error message as rake aborted.
spec/models/survey_spec.rb" --format html:result.html failed

On 10 Nov 2009, at 06:46, Amit K. wrote:

Yes i get an error message as rake aborted.
spec/models/survey_spec.rb" --format html:result.html failed

Have you looked in the survey_spec.rb file to see if there’s a problem
then? Does the ‘error message’ give you a line number to look at?

cheers,
Matt

+447974 430184

I checked the whole code but there is no error as such.
What i have done is i added a line i.e.
t.spec_opts = [’–format’ , ‘html:result.html’ ] under
/lib/tasks/rspec.rake i.e.
[:models, :controllers, :views, :helpers, :lib, :integration].each do
|sub|
desc “Run the code examples in spec/#{sub}”
Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
t.spec_opts = [’–options’, “”#{RAILS_ROOT}/spec/spec.opts""]
t.spec_files = FileList[“spec/#{sub}/**/*_spec.rb”]
t.spec_opts = [’–format’ , ‘html:result.html’ ]
end
end

After adding i am running the rake tasks as rake spec:models
RAILS_ENV=test

But it is giving me error as posted above.

Also is there is any other way to print output in an html file bu using
above rake command?

Amit K. wrote:

Any suggestions on the above topic

Hello,
I want to print my output in an html file.
I am using command rake spec:controllers --format html:result.html from
the root directory
But it is not working.
Please suggest

Any suggestions on the above topic

On Fri, Nov 27, 2009 at 3:21 AM, Amit K. [email protected]
wrote:

Amit K. wrote:

Any suggestions on the above topic

Hello,
I want to print my output in an html file.
I am using command rake spec:controllers --format html:result.html from
the root directory
But it is not working.
Please suggest

–format is a spec command option:

spec spec/controllers --format html:result.html

The rake task doesn’t support command line options.

Amit K. wrote:

Ok.Thanks a lot David

Hello,
Is there any way to display rspec result in .csv or .xls format.

Ok.Thanks a lot David

On Wed, Jan 20, 2010 at 5:03 AM, Amit K. [email protected]
wrote:

Amit K. wrote:

Ok.Thanks a lot David

Hello,
Is there any way to display rspec result in .csv or .xls format.

You can write a custom formatter and invoke it with:

spec spec --require my_formatter.rb --formatter MyFormatter

See
http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Runner/Formatter/BaseFormatter.html
for all the methods you’ll want to implement in the formatter.

HTH,
David

Thanks a lot David.
I generated a the output to xls with the command
“spec user_spec.rb --format progress:a.xls”
Under the xls it is displaying only those examples which are failing
like for e.g.

‘User User should not be created if email format is different’ FAILED
expected: “Please check the email format”,
got: [“is too short (minimum is 6 characters)”, “should look like
an email address.”] (using ==)
./user_spec.rb:39:

In html it looks like:

should not be created if email format is different
expected: “Please check the email format”,
got: [“is too short (minimum is 6 characters)”, “should look like
an email address.”] (using ==)./user_spec.rb:39:37 @user.email =
“abcd”
38 @user.should_not be_valid
39 @user.errors.on(:email).should == “Please check the email
format”
40 end

Now how can i change the code so that output in xls will look similar to
html atleast passing examples should be visible

I also wanted to know how and where i should write my custom formatter?
Also it would be good if i can see some links which contains examples of
the same