Patrick J. Collins | 24 May 02:12
Favicon
Gravatar

shared examples with a block for expects?

Hi,

Basically I want to do something like this:

describe FancyThingsController do

  def do_new
    get :new
  end

  def do_create
    post :create, :fancy_thing => { :some => "params" }
  end

  shared_examples "an access controlled action" do |expectation|
    it "denies access" do
      expect(&expectation).to raise_error(CanCan::AccessDenied)
    end
  end

  describe "#new" do
    it_behaves_like "an access controlled action", proc { do_new }
  end

  describe "#create" do
    it_behaves_like "an access controlled action", proc { do_create }
  end

end

(Continue reading)

Kleber Shimabuku | 24 May 00:27

received unexpected message :id= with (20)

Please help me to understand this error message:

 1) PostsController#create when logged in should create a new post and
redirect to a successful message page
     Failure/Error: post 'create', { post: {title: 'New post',
       Mock Post(id: integer, title: string, description: text,
location: string, created_at: datetime, updated_at: datetime, status:
string, tags: string, views: integer, user_id: integer) received
unexpected message :id= with (20)
     # ./spec/controllers/posts_controller_spec.rb:56:in `block (4
levels) in <top (required)>'

Finished in 0.59991 seconds
6 examples, 1 failure

I'm trying to figure out this for about a week or more :(

Attachments:
http://www.ruby-forum.com/attachment/7429/posts_controller_spec.rb
http://www.ruby-forum.com/attachment/7430/posts_controller.rb

--

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

How does Spork help in requests specs?

Even with Spork, my requests specs are very slow to start running (about 
7 seconds).

I suspect Rails is booting each time I run "rspec -X spec/requests".

Is that true? If so, is there any way I could instruct the web server to 
keep alive after the specs run so that it would be faster on next run?

Are there any resources on how to have better performance on running 
requests specs with Capybara and Webkit?

Having to wait about 7 seconds between consecutive runs is really a 
blocker for me. If I can't get it to run faster, I'll give up on 
requests specs and only have the controller's tests and client-side code 
specs without any integration tests...

But to be honest, I feel much more comfortable having some integration 
tests for the main features of my application and I would appreciate any 
hints on making them start faster.

The last time I worked with Rails, long ago, it wasn't such a painful 
experience to write such kind of tests (Capybara + Webkit). And my 
current desktop PC is *way* faster than it used to be by that time...

I understand that Rails is much slower to boot now, but maybe there are 
some tricks for reducing the need of rebooting between consecutive 
requests specs run.

Thanks in advance,
Rodrigo.
(Continue reading)

Peter Fitzgibbons | 15 May 13:32
Picon
Gravatar

Bash shim for Rspec

HI Folks,
The following script is *supposed* to run rspec under Jruby with the proper Java-switch for using SWT with OSX (-XstartOnFirstThread).
The issue is that this script doesn't actually run any of the specs!
Example:
$ bin/rspec_auto_jvm spec/swt_shoes/app_spec.rb
spec/swt_shoes/app_spec.rb
args are  spec/swt_shoes/app_spec.rb
$

Can anyone point out the flaw?

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org


#!/usr/bin/env bash
# !/usr/bin/env jruby --1.9 --debug
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

echo "$ <at> " | grep 'swt'

if [[ $ <at> == *swt* ]]; then
  swt_opt="-J-XstartOnFirstThread"
fi

echo 'args are ' $*

run_rspec="
# http://jira.codehaus.org/browse/JRUBY-6324
# random seed for srand is not initialized properly
# call once and throw-away nil default first value
x = srand

require 'rubygems'

version = \">= 0\"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'rspec-core', version
load Gem.bin_path('rspec-core', 'rspec', version)

exit 0
"

jruby --1.9 --debug ${swt_opt} -e ${run_rspec} $*


Patrick J. Collins | 15 May 08:47
Favicon
Gravatar

how can I do an "or" within the context of a matcher?

Capybara has two methods:

page.has_button?

and

page.has_link?

...  I am wondering, how can I make a helper method that will be
satisfied by one or the other?  In other words, I want to be able to do:

page.should have_link_or_button("blah")

def have_link_or_button(locator)
  have_link(locator) || have_button(locator)
end

But that doesn't work...  Is there any way to do this?

Patrick J. Collins
http://collinatorstudios.com

S Ahmed | 14 May 21:23
Picon
Gravatar

overview of how rspec was designed

Other than jumping into the codebase myself, I was wondering if anyone has done a high-level (or better yet low level) write-up on how rspec works under the covers?

Picon
Gravatar

Stubs and contract tests

Hey guys, could you help me (in)validating an idea?

As you might know, Contract tests solve a problem stubs have: if the object interface changes, the stubbed tests will continue passing.

In RSpec, it's common to use a shared_context to describe contracts, so both Posts and Comments tests would have PostsCommentsContract. If Comment's interface ever changed, Posts tests would present a failure wherever we ran it. However, it won't tell us which stubbed methods were invalid now; it just tell us the file that have invalid stubs.

If we had, for example, #stub_contract(:method), automatically raising a failure if its reference (double) object's interface changed, how would it be bad?

I'm trying to think the cons of it. Could you guys help me finding it?

--Alexandre
Patrick J. Collins | 10 May 06:14
Favicon
Gravatar

how do I test for a status code in a :js => true test?

I have a view with some javascript that does page redirection, and I
wanted to confirm that under certain circumstances the user will get a
500 error from CanCan::AccessDenied.

It seems that when I am not using :js => true, I can do:

page.status_code.shoud be 500

but.. when I try that in a :js => true example group, I get:
Capybara::NotSupportedByDriverError: Capybara::NotSupportedByDriverError

also the request and response objects are nil in the context of this
test...  My dirty workaround has just been to do:

page.has_content "CanCan::AccessDenied"

Which serves my purposes, but I was hoping for a better way...  Any
ideas?

Thank you.

Patrick J. Collins
http://collinatorstudios.com

Patrick J. Collins | 9 May 22:09
Favicon
Gravatar

is there a way to turn on :js => true in the middle of a spec?

Hi,

If I have a spec with some complicated background stuff--  like say for
example logging in...

it "does stuff", :js => true do
  fancy_login_helper_method
  visit somewhere_over_the_rainbow_path
  click_button "omg"
  page.should have_content("waka waka")
end

...  Is there any way to do something like :

it "does stuff" do
  fancy_login_helper_method
  js do
    visit somewhere_over_the_rainbow_path
    click_button "omg"
    page.should have_content("waka waka")
  end
end

So that I can cut down the time it takes to excute that test a bit?  Or
is that just impossible with the way headless vs browser stuff works?

Patrick J. Collins
http://collinatorstudios.com

Andrew Premdas | 9 May 18:01
Picon
Gravatar

stub.as_null_object mock and double

Hi there,


Is there any particular reason why stub is not stub.as_null_object by default?

Or alternatively is there some nicer sugar for stub.as_null_object

Is RSpec trying to discourage the use of stub.as_null_object, and if so why?

TIA

Andrew

--
------------------------
Andrew Premdas
Samer Masry | 8 May 19:55
Picon
Gravatar

Retrying specs

Is it possible to run an example without displaying it's
status ...F...
I'm currently using an around(:each) to run the spec and passing the
example block into vcr however occasionally the cassette needs to be
rerecorded.  I'd like to delay recording it as an error until it has been
retried.  Is that possible currently in rspec?

--

-- 
DryBlis - www.dryblis.com
Samer Masry | Rails Programmer
11 Ambler Ln, Emeryville, CA 94608
Tel.:510-991-7523 | Cel.: 714-814-8508

Gmane