[rspec-users] DatabaseCleaner and EmailSpec are looking for new maintainers

2013-09-11 Thread Ben Mabey

Hi all,
I'm looking for new maintainers for my DatabaseCleaner and EmailSpec 
gems.  If you use them and would like to contribute to the community by 
taking over one or both of them please let me know. DatabaseCleaner in 
particular could use more attention and has a lot of room for 
improvement.  For more details see this blog post:


http://benmabey.com/2013/09/11/databasecleaner-and-email-spec-need-new-homes.html

Thanks!

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Comparing files

2010-12-11 Thread Ben Mabey

On 12/11/10 2:03 AM, Matt Wynne wrote:

On 10 Dec 2010, at 16:21, Ben Mabey wrote:


On 12/10/10 8:56 AM, Matt Wynne wrote:

Hello folks,

I'm writing some tests for file upload code. The files are binary, images 
mostly. I'm futzing around a bit, trying to figure out how to assert that the 
uploaded file is the same as some golden master. If I do this:

File.read(uploaded_file_path).should == File.read(path_to_expected_file)

Then when it fails, I get an ugly diff of the difference between the binary 
files. So I'm about to invent something of my own. Has anyone got a good 
pattern for doing this already?

cheers,
Matt

I would compare the file's MD5 (or other) hash.  It won't tell you what is 
different.. just that they aren't identical which is what I think you want.   
So... something like:

Digest::MD5.hexdigest(File.read(uploaded_file_path)).should == 
Digest::MD5.hexdigest(File.read(path_to_expected_file))

-Ben

Great minds, Ben :)

I ended up with this:

https://gist.github.com/736421

cheers,
Matt


Yeah, that is a keeper... I don't know why my last email took several 
hours to reach the mailing list.  Very odd...


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Comparing files

2010-12-10 Thread Ben Mabey

On 12/10/10 8:56 AM, Matt Wynne wrote:

Hello folks,

I'm writing some tests for file upload code. The files are binary, images 
mostly. I'm futzing around a bit, trying to figure out how to assert that the 
uploaded file is the same as some golden master. If I do this:

File.read(uploaded_file_path).should == File.read(path_to_expected_file)

Then when it fails, I get an ugly diff of the difference between the binary 
files. So I'm about to invent something of my own. Has anyone got a good 
pattern for doing this already?

cheers,
Matt


I would compare the file's MD5 (or other) hash.  It won't tell you what 
is different.. just that they aren't identical which is what I think you 
want.   So... something like:


Digest::MD5.hexdigest(File.read(uploaded_file_path)).should == 
Digest::MD5.hexdigest(File.read(path_to_expected_file))


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where do a set the description on a should satisfy.

2010-09-27 Thread Ben Mabey

 On 9/27/10 8:23 AM, GregD wrote:


On Sep 27, 9:14 am, David Chelimskydchelim...@gmail.com  wrote:

On Sep 27, 2010, at 8:12 AM, David Chelimsky wrote:







re: how to include them: yes, in a module:

# in spec/support/custom_matchers.rb
module CustomMatchers
   ...
end

# in spec/spec_helper.rb
RSpec.configure do |c|
   c.include CustomMatchers
end


Okay, 1 more question and maybe this is more of a convention request.
I know in my rails apps that my environment is loaded when running my
specs from a rake task or from the spec command.  But for a non-rails
app, it would be nice to default spec program to load spec_helper if
it exists in the spec dir.  Like:

jruby -S spec spec

instead of having to do this to include the spec_helper every time:

jruby -S spec -r spec/spec_helper.rb spec

Or am I missing something?  Or is that just not desirable?  I know I
can use rake and create a rake task(s), but from the perspective of
the command line, it would be nice to not to have to supply the -r
option unless you want to include something outside of this
convention.



For rails and non-rails apps/libs the convention is to have each 
*_spec.rb file require the 'spec_helper' at the top of the spec like so:


http://github.com/rspec/rspec-core/blob/master/spec/rspec/core_spec.rb#L1

By following this convention you will only have to specify the spec on 
the command line.


HTH,
Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] How do I test my Module?

2010-09-21 Thread Ben Mabey

 On 9/21/10 6:51 AM, Gene Angelo wrote:

I think I understand basic Class testing, however, how do I test a
Module's behavior especially (in my case) where the Module will be used
as an extension primarily e.g. object.extend MyModule.

One option is to extend an object in your spec like so:

describe MyModule do
 subject { Object.new.extend(MyModule) }
 describe #foo do
  it does blah do
subject.foo.should == stuff
  end
 end
end

I often times will use an OpenStuct to help test modules because they 
allow you to easily set the state.  For example:


module MyModule
  def double
num * 2
  end
end

require 'ostruct'
describe MyModule do
  def new_object(hash)
OpenStruct.new(hash).extend(MyModule)
  end
  describe #double do
it doubles the num var do
  new_object(:num = 2).double.should == 4
end
  end
end

HTH,
Ben



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Re-using Rspec Matchers

2010-09-08 Thread Ben Mabey

 On 9/8/10 11:42 AM, Brian Kaney wrote:

Hey Everyone,

Is it good practice to call matchers from within matchers?   Kinda like this 
pattern:

   See: http://gist.github.com/570467

No, that should be avoided.  The problem is that the internal matcher 
will throw an exception that will bubble up and be reported.  Meaning 
that the parent matcher (link_one in your case) is not reported and the 
resulting stacktrace can be confusing.  Try something like this:


include_association(expected).matches?(actual)  
associate_one(expected).matches?(actual)


(Note, I have not tried the above but I think it should work.)

-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Mocking and specing command line (cli) execution, file operations etc. ?

2010-06-07 Thread Ben Mabey

Kristian Mandrup wrote:

What are the options for creating specs for file operations, executing
commands in the CLI etc.?

If I build a generator or something which runs a lot of things in the
command line, how do I check the results of these operations, fx
mocking file system updates and/or mocking the STDOUT/STDIN from the
terminal?

There must be some add-on libraries or options for this out there to
make it easy to accomplish.
  


In addition to aruba if you want to just use RSpec with StringIO objects 
you might find this example group handy:


http://github.com/bmabey/clispec/blob/master/lib/clispec/example_groups/runner.rb

The example group assumes you follow the runner pattern where your 
Runner class has a ::run method that takes args, out_stream, 
error_stream.  Many libraries use this pattern including Cucumber and 
RSpec.  The RSpec Book CLI app is setup this way as well if you want to 
see an in-depth example.


In general, for simple CLIs aruba is probably the way to go though.  
This example group is probably best if you want/need to use mocking more 
to avoid expensive operations.


HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Running code on error

2010-04-30 Thread Ben Mabey

Ryan S wrote:

Well, I am using SauceOnDemand with rspec. So when a test fails I want
to download the video that corresponds to the failing test. I figured
I could do a:

it should download video do
  begin
#some failing test here
  rescue Exception = e
#download video
raise e
  end
end

But this would get very repetitive for every rspec test.
  


Have you investigated creating a custom formatter?  I think that 
approach might be better suited for what you are doing.  It has been a 
while since I've dug into that code but I imagine that the exception 
will be passed to you for inspection. 

If that doesn't suit your needs you will have to decorate 'it' on 
ExampleGroup.


-Ben



On Apr 29, 7:31 pm, Pat Maddox mailingli...@patmaddox.com wrote:
  

Could you share a bit more about what you are actually trying to achieve?

On Apr 28, 2010, at 1:51 PM, Ryan S wrote:





describe Test do
 after(:each) do
 if ERRORS #execute custom code here
 end
  
 it should explode do

   #Test.explode -- fizzle
   Test.explode.should == KABOOM
 end
end
  
Let's say I have the above test and the validation fails and I want

some sort of custom action to take place. Is there a way to do that?
This is a very simplified example but I am just curious if it is
possible.
___
rspec-users mailing list
rspec-us...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  

___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

--
You received this message because you are subscribed to the Google Groups 
rspec group.
To post to this group, send email to rs...@googlegroups.com.
To unsubscribe from this group, send email to 
rspec+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/rspec?hl=en.


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] How to test an app with multiple databases?

2010-03-08 Thread Ben Mabey

David Chelimsky wrote:

On Sun, Mar 7, 2010 at 10:11 AM, Russell Fine li...@ruby-forum.com wrote:
  

David Chelimsky wrote:


On Sun, Mar 7, 2010 at 9:45 AM, Russell Fine li...@ruby-forum.com
wrote:
  

Our app connects to two databases. �The main database (through
ActiveRecord::Base) is automatically cleared before each test. �How do I
force the clear of the secondary database as well ?


There's no implicit support for this, so you'd have to do something
manually in a before(:each) block. You can do that in the
configuration (usually in spec_helper):

Spec::Runner.configure do |c|
  c.before(:each) do
# clear out 2ndary db
  end
end

HTH,
David
  

Thanks for the quick reply.  Do you happen to know where in the
framework I would call to clear out the db?  I can obviously do it
myself by hand by just deleting all elements, but I'm worried that the
testing framework may perform some unique actions that differ from what
I would do.



rspec-rails just wraps the rails testing framework facilities, so
whatever you're looking for is going to be found in the rails code.

I'm not sure how the database_cleaner gem handles multiple databases,
but you might find your answer there.

Can anybody else point Russell in the right direction?
  


DatabaseCleaner doesn't support multiple databases ATM.  I have had some 
discussions with people about adding support for multiple database types 
(i.e. AR and MongoMapper in the same app) but haven't thought about 
multiple DB connections for the same adapter.  Off the top of my head I 
don't think it should be too difficult to do for AR.  It sounds like you 
are using the standard rails transactional rollbacks for your tests 
right now.  In order to clear out your second database in a similar 
fashion (with transactions) I would try something like this in your 
spec_helper:


require 'database_cleaner'
DatabaseCleaner.strategy = :transaction

Spec::Runner.configure do |c|
 c.before(:each) do
   ActiveRecord::Base::establish_connection :secondary_db
   DatabaseCleaner.start
   ActiveRecord::Base::establish_connection :primary_db
 end

 c.after(:each) do
   ActiveRecord::Base::establish_connection :secondary_db
   DatabaseCleaner.clean
   ActiveRecord::Base::establish_connection :primary_db

 end
end


I haven't tried the above code but it seems correct.  Give it a try and let me 
know if it works.  If it does I could add support to DatabaseCleaner so you can 
select which AR DB connections you want to clean.

HTH,
Ben



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] testing named_scope

2010-01-23 Thread Ben Mabey

David Chelimsky wrote:

On Mon, Jan 18, 2010 at 4:01 AM, Pat Maddox mailingli...@patmaddox.com wrote:
  

On Jan 17, 2010, at 6:17 PM, Nin wrote:


Hi! I'm new to rspec and was wondering how named_scopes are usually
tested? Is it enough to test that it's defined? or do you need to test
the behavior as well? I've been reading around and this seems to be
the tester's choice, i just want to get people's opinion on this :D
  

class User  ActiveRecord::Base
 named_scope :admins, :conditions = {:admin = true}
end

describe User, admins do
 it should include users with admin flag do
   admin = User.create! :admin = true
   User.admin.should include(admin)
 end

 it should not include users without admin flag do
   admin = User.create! :admin = false
   User.admin.should_not include(admin)
 end
end



Small style matter, but I've leaning towards more declarative sounding
example names:

describe User, .admins do
  it includes users with admin flag do
admin = User.create! :admin = true
User.admin.should include(admin)
  end

  it excludes users without admin flag do
non_admin = User.create! :admin = false
User.admin.should_not include(non_admin)
  end
end

class User  ActiveRecord::Base
  named_scope :admins, :conditions = {:admin = true}
end

We still have 'should' in the examples, but this produces more
'spec-like' output:

User.admins
  includes users with admin flag
  excludes users without admin flag

FWIW,
David
  


Another small style matter.. I like using the :: notation for class 
methods as that is what the documentation tools tend to use (RDoc and Yard):


describe User, ::admins do
...
...
end


On the topic of RSpec as a form of documentation has anyone used the 
yard-doc rspec plugin?  It appears to be pretty limited ATM but seems 
very cool with a lot of potential.  Just like Ioke's docs it embeds the 
specs as part of the documentation with the option to view the source.  
Here is the example from the projects home page:


http://lsegal.github.com/yard-spec-plugin/String.html#pig_latin-instance_method

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] running specs on JRuby w/nailgun

2010-01-21 Thread Ben Mabey

Hi all,
I know this is probably more of a JRuby question but I'm guessing that 
people on this list may have gone down this path before.  At work we are 
starting a new project using JRuby.  The startup speed for testing an 
app is very painful.  Nailgun helps a lot with that.  It only helps with 
the slow startup time of JRuby though and does not address the use case 
of having gems preloaded like Spork does for MRI.  We would like to have 
all of our gems (esp Rails) preloaded in Nailgun so we can run our tests 
against it with minimal startup time (just the loading of the app and 
specs).


Has anyone solved this problem to get lightning fast specs on JRuby just 
like we can with MRI and Spork?


Thanks,

Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Spec helper configuration problem

2009-11-27 Thread Ben Mabey

Andrew Premdas wrote:

Hi all,

I have a rails application whose specs run on about eight different 
boxes, but I can't get them to work on my integration server. The bit 
thats breaking concerns some modules that I have in 
spec/support/modules which are loaded by

the following line in spec_helper

# get any macros etc
Dir[File.dirname(__FILE__) + /support/**/*.rb].each {|f| require f}


one of these modules includes the other modules, and this generates 
the following stacktrace

 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:440:in
 `load_missing_constant': uninitialized constant 
OrderSpecHelper::BasketSpecHelper (NameError)
 from 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in
 `const_missing'
 from ./spec/helpers/../support/modules/order_spec_helper.rb:2
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in 
`gem_original_require'
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in 
`require'
 from 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:158:in
 `require'
the line causing this is order_spec_helper.rb:2

  module OrderSpecHelper
include BasketSpecHelper
  
and BasketSpecHelper is defined in 
/support/modules/basket_spec_helper.rb



and is coded something like

  module BasketSpecHelper
...

I wonder if anyone has any ideas about the cause of this problem or 
some ideas about possible solutions


I've ran into similar issues.  The problem in my case was the my 
integration server was running linux but our dev boxes were OSx.  The 
issue was file ordering being different for the Dir::[] method on the 
OSes.  Try adding a sort call like so:


Dir[File.dirname(__FILE__) + /support/**/*.rb].sort.each {|f| require f}

HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] spec_helper getting reloaded after specs run under Textmate/Spork

2009-11-23 Thread Ben Mabey

David Chelimsky wrote:



On Sat, Nov 21, 2009 at 12:28 AM, Elliot Winkler 
elliot.wink...@gmail.com mailto:elliot.wink...@gmail.com wrote:


I'm having the hardest time trying to figure out something weird
I've suddenly run into. So I'm using Spork to run my specs.
Naturally I've got TM_RSPEC_OPTS in Textmate set to --drb and I'm
running `spork` from the command line to fire up the Spork server.
However, if I have a spec file open in Textmate and I press
Command-R, then the specs in the file get executed twice. I did a
quick test by having spec_helper print out something at the bottom
of the file and then wrote up a quick one-example spec file. When
I ran it, I saw the spinner spin, the debug line got printed to
the window, the output from the specs appeared, and then the
spinner spun some more and the debug line appeared again (but a
duplicate set of specs didn't appear because I think RSpec's smart
about not re-running tests). So it definitely looks like
spec_helper is getting loaded again, after all the specs are run.
(I know spec_helper should be run twice, once during preloading,
once during execution. But not again, AFTER execution.)

At first I thought it might be only specific to my project, but I
tried creating a fresh Rails project, installing RSpec into it,
and creating and running a quick spec file, but the same thing
happened -- spec_helper seems to get loaded again. I also tried
wiping and reinstalling the rspec, rspec-rails, and spork gems,
but that didn't work either.

Just to emphasize, this is only when Spork is running. If I leave
TM_RSPEC_OPTS at --drb but fail to leave the Spork server open,
the specs only get run once as they should.

Also, this is only for Textmate -- I've got --drb in my spec.opts
and `rake spec` works just fine when Spork is running.

So I really don't know who the culprit is: Spork, RSpec bundle, or
maybe it's just me. I noticed in Lighthouse a few people have had
this same problem, but those were a while back and anyway this
seems to be different.

David, can you think of a reason why something like this would be
happening? Exit status maybe? Or maybe this is more of a Spork
question.


Sounds like a spork question to me :) I was able to duplicate your 
experience, but I don't have any initial thoughts about why this would 
be happening.



Hmm.. I can't think of why this would happen either.  Tim Harper is a 
textmate user so if you post this question to the spork mailing list he 
could probably help you.  (Spork ML: 
http://groups.google.com/group/sporkgem)


-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] testing Rake tasks with FakeFS

2009-11-01 Thread Ben Mabey

Jake Benilov wrote:

Hello Ben,
  


Hi Jake,
I hope you don't mind but I am copying this response to the rspec-users 
list in case any one else is able to shed more light on it.

I have a bit of a newbie question regarding fakefs; I want to test Rake
tasks using fakefs and rspec:



require 'fakefs/safe'
require 'rake'
require 'spec'

task :create_file do
  touch /abc
end

describe my rake script do
  before do
FakeFS.activate!
  end

  it should create a file abc do
Rake::Task[:create_file].invoke
File.should exist(/abc)
  end

  after do
FakeFS::FileSystem.clear
FakeFS.deactivate!
  end
end


When I run this, a real file /abc is being created on the filesystem. I
am guessing that this has to do with the fact that the touch method
isn't FileUtils.touch, but rather that FileUtils is being included into
Rake and thus touch is not being mocked out.

Is my analysis correct? In any case, is there a way that you can think
of to write such a spec?
  


I've never tested a Rake task with FakeFS before so I looked into a 
bit.  In short, I think your analysis is correct.  However, it is a bit 
confusing because Rake does in fact use FileUtils::touch.  I discovered 
that when you fully qualify FileUtils::touch in the rake task then it 
works fine.  I stepped into rake's call to 'touch' and it seems to be 
doing some other logic specific to rake.  My hunch is that rake somehow 
retains a handle onto the original FileUtils const even though it is 
replaced by the fake ones with FakeFS.  I'm not familiar with Rake's 
code base so I can't say that for sure or how to really fix it.  
However, you can fully qualify the call if you want to but that will be 
going around some rake logic and may have some undesired effects (I 
can't think of what though).  I'm sure someone more familiar with Rake's 
code could offer a better solution.  Here is a gist of my explorations 
in case anyone else wants to play around with it:


http://gist.github.com/223989

HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [BDD] View specs and cucumber -- duplication of effort?

2009-10-28 Thread Ben Mabey

nruth wrote:

Hi Guys

I'm going to put the cat amongst the pigeons here in the hope of some
clarity falling out of the sky on me.
My question is this: In a world with Cucumber what is the value of
view specs?

In the community (railscamp, for example) there are a fair number of
people using Cucumber and skipping view specs, but still speccing
controllers, models, tricky view helpers and so on.

Why? Because they don't find them helpful. Indeed they are seen as a
waste of time (money) not only duplicating Cucumber coverage, but also
introducing a high-maintenance example group which designers (who
don't run tests) will frequently break.

These people aren't stupid. They're producing working apps. I don't
claim that their work cycle is perfect: this is about utility and
efficiency, or about being lazy or avoiding boredom, if you prefer.

I've been working in a mixed environment, with an existing project
which uses rspec and cucumber (sans view specs) and my own green field
app for a different client.
I've been following the BDD approach prescribed by the RSpec book (or
so I think). This works, and has produced a lot of LOC.

I've not worried, as it has given me plenty of practice with the
various arms of rspec, webrat, and other tools.
Now that I'm more comfortable with them things are starting to get
tiresome, especially duplication, and I'm worried I'm creating a
monolith. Too many specs = TLDR ?

What should I try using view specs for? Why are they better than
cucumber for this?

Driving views through examples helps us think about what the view
needs in order for it to do its job. It encourages us to write the
code we wish we had to fulfil those needs.

I'm not sure how this is any different to what I do in the outer
circle with Cucumber. If I write an explicit scenario like
http://gist.github.com/221004 then I already know what the view needs
to let me do.

If I write something more broad-brush (which you will do, if quickly
sketching out features during a design meeting) like When I add a
page link I have to then define that step so it goes red (or, heaven
forbid, green). But to write that step definition I have to know how I
can interact with the page. This example actually comes from a broad-
brush step being expanded in the scenario itself rather than hiding it
away in a step definition, but that's a different subject.

I'm specifying the page's behaviour in the scenario, or in the step
definition. Why duplicate this process with a view spec?

I keep coming back to the introduction of chapter 23 in the RSpec book
but don't seem to be getting anywhere from it.

For the time being I'm going to keep writing view specs, but try to
make them lighter and cut some of the dead wood by describing unusual
or interesting behaviour rather than all behaviour.

I'd love to hear your thoughts.

Regards

Nick
  



Hi Nick,
View specs can be useful but they can also be very brittle and add undue 
maintenance to a project.  The brittleness, which causes a lot of 
maintenance headaches, usually is caused by specing the design and 
structure too closely.  If the designer changes the layout this 
shouldn't break the view specs IMO.  I think a good strategy is to avoid 
this is by keeping things very general (as much as you can).  For 
example, you should only verify if the correct text was displayed 
instead of focusing on the HTML structure.  Verifying that certain 
elements are present via their ids but not tag type or css class which 
are subject to change by the designer will also help reduce brittleness.


I'm also of the opinion that view specs *only* make sense on large 
complicated views.  An example of such a page would be a users profile 
page on a social network site.  A lot of stuff is generally displayed on 
a page like that.  Setting up all the data required to test that via 
Cucumber can be very expensive/slow and cucumbersome.  (Especially 
considering that such a page will contain random data and be 
personalized to the person viewing the profile.)  Being able to isolate 
all of that complexity and test it individually with view specs (and 
probably with a Presenter and corresponding spec) will make your life a 
lot easier and actually save you time and from maintenance headaches.  
For simple pages that are already being exercised via Cucumber view 
specs are overkill IMO.  A simple form submission and checking the 
presence of some basic text is well within the bounds of what Cucumber 
should be testing.  If you are finding you want to write Then I should 
see.. And I should see.. And I should see., etc that is an indication 
that a view spec *may* be helpful in that situation.


HTH,
Ben



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Can't figure you why I am getting deliver_from == Nil Using EmailSpec

2009-10-22 Thread Ben Mabey

Tom Hoen wrote:


Using EmailSpec, I am testing the format of emails sent from an observer.

 

I can verify the deliver_to address, the bcc_to address, and that the 
message body has the appropriate text.




How are you verifying this?


 

However, when I test the deliver_from, I am getting an error saying my 
deliver_from is nil, though when I follow the same steps in 
development, an email is sent with the appropriate from address. This 
is the message I am getting:


 

'Event Notification should be sent from an address with the event 
description' FAILED


expected #TMail::Mail port=#TMail::StringPort:id=0x7342b8a 
bodyport=#TMail::StringPort:id=0x733f598 to deliver from mytest 
Classroom 42 : Janet Teacher1 myem...@this.com, but it delievered 
from nil


 


Any insight you can provide would be greatly appreciated.




deliver_to's matches? method is as follows:

 def matches?(email)
   @email = email
   @actual_sender = (email.from || []).first
   @actual_sender.eql? @expected_email_addresses
 end

On the email you are testing can you call 'from' on it and see what it 
returns?


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Mailing list for BDD?

2009-09-27 Thread Ben Mabey

Ed Howland wrote:

Sorry for the cross post, but does anyone know of a list dedicated to
just BDD? Seems like all the discussion is happening over on
rspec-users, some on the tdd list.

My interest is in the abstract concept of behavior driven
design/development, as expressed by Dave Astels and Dan North and
others.As opposed to a specific framework, like rSpec, ScrewUnit and
others.

Would it be appropriate to create such a list, if none exists?

Thanks.
  


http://groups.google.com/group/behaviordrivendevelopment
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Problems while loading 'spec/stubs/cucumber'

2009-09-15 Thread Ben Mabey

Rodrigo Flores wrote:

Hi

I'm reading the rspec book and I'm having problems when I require the 
file 'spec/stubs/cucumber'. When I go to an IRB prompt and type 
require 'spec/stubs/cucumber' after requiring another libraries [1] I 
get the false in 'spec/expectations' and an error in 
'spec/stubs/cucumber'. The error message is [2]. Any ideas? I'm using 
rspec 1.2.8.



Thanks in advance




[1]

require 'rubygems'
require 'spec'
require 'spec/expectations'
require 'spec/stubs/cucumber'

[2]
NoMethodError: undefined method `Before' for main:Object
from 
/home/rodrigo/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/stubs/cucumber.rb:3
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in 
`gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in 
`require'

from (irb):9
from :0



That file is only meant to be used when running Cucumber.  So you would 
place the require in your features/support/env.rb file for example.  
Without having Cucumber loaded first the Before method will not be 
defined and the above error is expected.


If you are just wanting to play around with rspec matchers in IRB then 
the top three requires is all you will need.  So, you could say:


require 'rubygems'
require 'spec'
require 'spec/expectations'

42.should == 42

HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] arbitrary handling of received messages in mocks

2009-08-25 Thread Ben Mabey

Chuck Remes wrote:
I am trying to process a message sent to a mock to verify it contains 
the correct keys. In my case I am sending a JSON string to the mock 
built from data passed in via the test. The object internally builds a 
hash and then constructs the JSON string from it.


I can't get my mock to fail though. Here's an example similar to what 
I've got.


describe Foo
  it should match the json string do
# setup stubs  mocks
...
hsh = ... # keys and values used inside the method
@api.should_receive(:publish_to_bus) do |message|
  false # should always fail
end

Foo.new(@api).decode hsh
  end
end

The documentation says the expectation passes or fails based upon the 
return value of the block. I can't even force it to fail by returning 
false. Once I figure this out, I plan to decode the JSON string in the 
mock block and compare the resulting collection with the data I 
originally passed in to the object. This behavior will likely become a 
helper method (if that matters).
The docs could wrong.. I dunno  When using the block form I always 
set expectation within the block.  This may be the wrong way to use it, 
but it works.  Like so:


describe Foo
 it should match the json string do
   # setup stubs  mocks
   ...
   hsh = ... # keys and values used inside the method
   @api.should_receive(:publish_to_bus) do |message|
JSON.parse(message).should == hsh # or whatever you need to do 
here.

   end

   Foo.new(@api).decode hsh
 end
end



-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] running rake spec:remote

2009-08-25 Thread Ben Mabey

oren wrote:

When running autotest only 'rake spec' is running
and I want it to run 'rake spec:remote' as well.

How do i achieve that?

  


IIRC, autospec (not autotest) does not use rake at all.  It uses the 
opts defined in spec/spec.opts.  I would suggest making any needed 
changes in that file.


HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] testing emails with celerity - the best solution

2009-08-23 Thread Ben Mabey

Matt Wynne wrote:


On 22 Aug 2009, at 13:09, Sławosz Sławiński wrote:


Hi,
I'm trying to test emails with Celerity. The problem is, because
Celerity browser uses environment 'cucumber', but Cucubmer runs in
'test'. Emails steps are running in 'test', so it is impossible to check
mails send in 'cucumber'. I think, I can use webrat for steps with email
sending, and cucmber for others (i.e. wiht Ajax). But maybe there is
more logical and elegant solution?


I'm not sure, but I think it's more likely the problem is that your 
tests are running in a different process to the app you're testing, so 
the usual railsey mail testing stuff doesn't work.


We got around this by writing the emails to disk, then having the 
tests check the files on disk to validate the emails. Could that work 
for you?



I agree with Matt.  You have three options to address this:

1. Run your server is the same process as Cucumber.  If you are using 
Rails then I'd reccomend the mainline lib: 
http://github.com/gaffo/mainline/tree/master  If you are using another 
Ruby framework this is trivially done by starting up the server in a new 
thread.


Or.. you can go the route Matt suggested.  If you are using email-spec 
you can use active record mailer or action mailer cache delivery.  The 
ActiveRecord Mailer will work out of the box right now.  For the 
ActionMailer cache lib you will need to use these forks ATM:


http://github.com/liangzan/action_mailer_cache_delivery/tree/master
http://github.com/liangzan/email-spec/tree/master

I plan on merging the above into email spec soon.

Even if you are not using email-spec then the above libs would be helpful.

-Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] undefined method 'mock'

2009-08-23 Thread Ben Mabey

Jesterman81 wrote:

Greetings,

I am trying to use the mock method in rspec and it returns a undefined
method 'mock' error.  I am using this with the rspec book in chapter
6.3.  Do I have to configure rspec someone.  I have gem rspec 1.2.8
installed and using ruby 1.8.

any help will be appreciated.

  



Please post the failing spec and your spec_helper.rb.  Without those it 
is hard for us to diagnose the problem.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Sharing code and still keeping a only commit if all is green discipline

2009-08-20 Thread Ben Mabey

David Chelimsky wrote:

On Thu, Aug 20, 2009 at 7:00 PM, Marcelo de Moraes
Serpacelose...@gmail.com wrote:
  

Hello list,

I'm working in a big project in the company I'm working on as a BDD
tech lead, this means I'm leading the implementation of BDD in
ongoing projects, most of them did not use BDD from the start.

I implemented the policy of Only commit if all your tests are
passing, this in all tests abstraction levels: From Cucumber features
, scenarios, steps and rspec specs.

The point of this rule is: Never commit partial code. If it's not
done/fully working (as the feature/specs say it should), don't commit
it.

However, a co-worker of mine came to me and said that partial commits
are needed to share code. I don't agree with that, I think we can use
patches or branches to do that (like a development branch) but at
least one branch should have only stabe/deliverable code.

For patches, however, he mentioned that we might have conflicts/code
duplication, where the guy who shares the patches will have problems
later on when pulling from the server (he already had part of the code
that was committed).

What do you think? I'm looking for some enlightenment! Any
contributions welcome.



We use remote branches (we use git) to collaborate and share code that 
isn't ready to be merged down to our mainline.  Then when that branch is 
ready to be merged down we use git rebase --interactive to squash all 
the wip/garbage commits.  This gives you the best of both worlds IMO.  
Using rebase can be dangerous though as it rewrites the repo's history.  
That means once someone rebases everyone will have to delete that branch 
and pull it again if they want to continue working on it.  That is why 
we generally wait until the work on the branch is don't before we rebase.




My approach, which is not mine originally, nor very unique, is follows:

All developer specs (RSpec) should always be passing.
Previously passing customer specs should continue passing.
Customer specs for features in development are allowed to fail.

You can enforce those rules in a CI build in any number of ways.
Tagging features in development as @in_development, for example, and
not running those as part of the CI build, or running them separately
but allowing them to fail without considering the build a failed
build.

That all make sense?
  



Cucumber actually ships now with some additional rake tasks to help with 
this:


rake cucumber  # Alias for cucumber:ok
rake cucumber:all  # Run all features
rake cucumber:ok   # Run features that should pass
rake cucumber:wip  # Run features that are being worked on


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] specify a port for DRB

2009-08-12 Thread Ben Mabey

Chris Flipse wrote:

Pardon the crosspost, but this applies to both

So, at work, I'm one of several people developing on the same 
multi-user unix system.  I/we would like to be able to use the drb 
server, but at the moment rspec,cucumber and spork assume a single 
well known port number for drb.  That doesn't work well on a 
multi-user system.


My itch, and I'm starting to look through the codebases to scratch 
it.  I'm planning on patches for spork and cucumber as well.


There are two ways I can see to implement this, just wanted to see 
what people thought about it.  The first is through an environment 
variable, and  the second is through adding command line switches.


adding the switches to the command lines seems like it will be more 
invasive, and it would require people to remember to specify the port 
on any manual invocations.  Also need to pass the right port in to 
your spork invocations.  On the other hand, it's more consistant with 
the way the rest of the options are specified, and could be set in an 
indivudual user's cucumber.yml or spec.opts, mitigating the command 
line issue (though, frequently, I don't use my spec.opts file)


setting an environment variable, say RSPEC_DRB or CUCUMBER_DRB would 
be much less invasive, since the main codebases specify their global 
drb ports through a constant anyway.  It'd be fairly easy to have them 
check for an environment variable before accepting the default.  I'd 
just have to add the ability to specify a specific port to spork.  
Downside is that it's not as consistant with the rest of the 
configuration.  Upside from a user perspective is that it's completely 
fire-and-forget; just set an env variable in your .profile, and you're 
done worrying about it...



Thoughts?



I can see where you are coming from and understand the tradeoffs...  It 
would be nice just to set an ENV var and have both cucumber and spork 
operate on it.  It does feel a little dirty though and could result in 
confusion if they were ever misspecified.  It is also harder to document 
the use of constants, whereas the the options already have a 
convention.  For the sake of consistently I would rather see them be 
specified using options.  Does anyone else have a preference or argument 
for using env vars?


BTW, thanks for doing this. :)


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [cucumber] table.hashes

2009-07-28 Thread Ben Mabey

Yi Wen wrote:

Hi,

I had a couple features failed with cucumber 0.3.90 because 
table.hashes is frozen so I cannot change the hashes anymore. Just 
wonder what's the reason behind the change? Thanks


Yi

 
___

rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users



This change was added to avoid unintended side effects... I can't 
remember the exact use case though.  If you need to modify it call #dup 
on the hashes first.  Also, please use Cucumber's mailing list in the 
future:


http://groups.google.com/group/cukes

Thanks,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] On Mocks vs Stubs in the context of rSpec

2009-07-25 Thread Ben Mabey

Rick DeNatale wrote:

On Thu, Jul 23, 2009 at 8:41 PM, Ben Mabeyb...@benmabey.com wrote:
  

You can, IMO, use a mock like a stub and a stub like a
mock.. Take this for example:

describe #some_method do
 it delegates to some_obejct do
  some_object = stub('some object', :some_method = foo)
  my_object = MyObject.new(some_object)

  my_object.some_method.should == foo
 end
end

We are using a stub as a dummy object, and yet our expectation is clearing
testing the method call.  So is the above a stub or is it really a mock?  I
would say that it is acting like a mock.  I hope that others on the list
will correct me if I am wrong making this observation/conclusion.



Well, I'm not sure.

There's a difference here.

The stub simply sets things up so that IF some_object receives
:some_method it will return 'foo' instead of something else (including
a method_missing error).

If the implementation looks like:

class MyObject
def initialize(obj)
end

def some_method
   foo
end
end

Then the stub object proves nothing, the example will succeed whether
it's there or not.

On the other hand using a mock and setting a message expectation
asserts something about the implementation of some_method and it's
relationship to the intialize method.  It's more gray-box than
black-box.
  


True, but I think the difference is very small in this case.  In the 
delegation example we want to ensure that the other method is called and 
that it's return value is returned.  Adjusting your implementation 
slightly you could still make the message expectation version pass as 
well but still be a false-positive:


class MyObject
   def initialize(obj)
   end

   def some_method
some_object.some_method
  foo
   end
end


In both cases another example would be needed to point out the problem- each of which 
would rely on returning another canned response.  Of course, using triangulation for 
something small as delegation is just plain silly. :)  FWIW, I would set a message 
expectation when specifying delegation.  However, to my point if a stub is being used in 
this manner I think it is crossing the line of being a dummy object and taking on more of 
a mockish like role.  Perhaps it is going overboard to say that it is being 
used as a mock, but the intent feels the same in this case IMO.


-Ben






___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] How detailed should error scenarios be?

2009-07-24 Thread Ben Mabey

Nathan Benes wrote:

I'm fairly new to cucumber and rspec but so far am falling in love with
both.  I've read up on several different articles concerning these
testing tools including the 'beta' BDD rspec/cucumber book.

I saw this thread here:  http://www.ruby-forum.com/topic/183428

Which concerns how small or detailed specs and scenarios should be - and
the basic gist was to keep scenarios at a higher level and leave the
detailed form
fields etc to rspec specs.

This was all wonderfully insightful but it brings me to another
question.  How detailed (or should they be included in cucumber tests at
all?) should the error path be?  Happy paths are great to test, but
it's also necessary to test error paths so that users aren't
encountering rails stack traces, empty feedback, etc.

Should there be one scenario per empty field?  Should there be one
scenario per validation check per field?  Should it be condensed to a
single scenario that attempts to encompass all error paths?

I have one specific, seemingly overly complicated scenario that attempts
to go the one scenario per validation check per field route:

  Scenario Outline: Add account with invalid fields
Given I am logged in as BudgetTest
And I am on the New Account page
When I fill in the form for account account_name with valid data
And I submit the data value1 for the field_type1 field,
field_name1
And I submit the data value2 for the field_type2 field,
field_name2
And I press Add Account
Then I should see the rendered template for the new account page
And I should see an error indicating field_name was error


I've removed the Scenarios:  blocks because they would wordwrap and look
terrible/undreadable.  Following this is two sets of scenarios:

Scenarios: missing required fields

Scenarios: submitting bad data

Some of the fields compare data with each other to determine validity
which is why there's two data entries in the scenario outline.  If the
second is left blank then the defaults that were set in When I fill in
the form... are used for it.  Each Scenarios block contains a table
with a of the fields defined by  in the outline.  As you can see,
it seems to me to be overly complicated, overly verbose, and perhaps
doing more than it should be.

I think maybe this test goes overboard...but what level of detail is
good for error-path testing?
  


Hi Nathan,
I think testing all of the validations from Cucumber is going overboard 
*unless* the customer wants to see them there.  I have done something 
like that but it was when I was writing my own validation logic (in this 
case I wasn't even using AR or another standard library). It was a nice 
way of showing the customer what were and were not valid values.  
However, if you are using ActiveRecord to do standard validations then I 
see little value in checking each validation separately.  It will take a 
long time to run and it seems like it would really not add much value in 
terms of regression catching beyond what the fast model-level code 
examples would provide. So, like I said, the only value I would see in 
that would be for a customer to see that it is working as they want it to.


In general, I like to keep happy paths in Cucumber features along with 
some special error cases.  Driving though the entire stack is a 
double-edged sword.  It provides great regression testing and is an 
excellent way to frame scenarios for customers.  However, the number of 
execution paths you can execute from such a high level is inherently 
limited... the number of objects and all of there potential states in 
concert with one another results in a combinatorial explosion of number 
of test cases required to test everything.  That is why isolated specs 
on a lower level are still very valuable and for me provide a great deal 
of confidence when used along side some happy-path full-stack tests.  
(And even then you can never test everything...)


Thats my current take on things at least... HTH,

Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] On Mocks vs Stubs in the context of rSpec

2009-07-24 Thread Ben Mabey

Marcelo de Moraes Serpa wrote:

Thanks David and Ben for the comprehensive replies! I really appreciate it :)

These wikipedia articles helped me to understand on the more conceptual level:

http://en.wikipedia.org/wiki/Method_stub
http://en.wikipedia.org/wiki/Mock_object

So, if I understand it right -- Stub is for methods and Mocks are for
roles (or, in the technical-level -- objects).

In the context of rSpec/rSpec-Rails, however,  the API makes it
confusing, to be honest. Being able to create a Mock with
Spec::Mocks:Mock with Spec::Mocks::ExampleMethods# confuses me.
  
Hmm.. I can see your point as far as where the methods live being 
confusing.  Reading about stub method in the RDoc pages for mock methods 
does seem odd.  The reason, as David, pointed out is really more due to 
reducing code duplication between the two.  Any suggestions on making it 
better?




The same applies for stub_model() and mock_model(). I know that
mock_model is a convenience method that can be used to create an
object with an API similar to ActiveRecord::Base's. The API says
stub_model is basically the same, but prevents the object from
accessing the database. Ok, but why attaching these concepts to Stub?
Is this the right name to use for this method? (Stub == mock object
that is not allowed to access the database?).
  
I think you raise a good question whether or not stub_model is a best 
name for the functionality it provides.  I think stub_model is really 
called a partial stub.. or partial mock.  Hmm.. I'm not quite sure what 
the correct name is.  But basically, as you said, it is the real object 
but is not allowed to touch the DB.  So it is there for performance 
reasons mostly.  mock_model however gives you a dummy object with some 
predefined stubbed methods that you typically want for an AR object 
(i.e. #id).  However, it is very true that in many cases you will be 
using this mock_model as a stub.  I can see how having stub_model can 
cause confusion...


Perhaps, a better API would be to alias stub_model to mock_model (this 
would be more aligned with the #mock and #stub API) and then have a 
partial_stub_model or stub_model(Model, :partial = true)?   Changing it 
now I'm sure would make some people upset but it could be done with 
deprecation warnings if it is causing that much confusion... This would 
really be David's call to make and I'm guessing he had some good reasons 
for making the decision he did in the first place.



And there's the  Spec::Mocks::Methods#stub method, which is the one
that reflects the concept that the Stub is a dummy method.
  


Again, this is due to the implementation..  I see your point, but I 
don't know if the typical user really cares where it lives.  Perhaps a 
little explanation in the RDoc would be sufficient to avoid confusion?


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] How detailed should error scenarios be?

2009-07-24 Thread Ben Mabey

Ben Mabey wrote:

Nathan Benes wrote:

I'm fairly new to cucumber and rspec but so far am falling in love with
both.  I've read up on several different articles concerning these
testing tools including the 'beta' BDD rspec/cucumber book.

I saw this thread here:  http://www.ruby-forum.com/topic/183428

Which concerns how small or detailed specs and scenarios should be - and
the basic gist was to keep scenarios at a higher level and leave the
detailed form
fields etc to rspec specs.

This was all wonderfully insightful but it brings me to another
question.  How detailed (or should they be included in cucumber tests at
all?) should the error path be?  Happy paths are great to test, but
it's also necessary to test error paths so that users aren't
encountering rails stack traces, empty feedback, etc.

Should there be one scenario per empty field?  Should there be one
scenario per validation check per field?  Should it be condensed to a
single scenario that attempts to encompass all error paths?

I have one specific, seemingly overly complicated scenario that attempts
to go the one scenario per validation check per field route:

  Scenario Outline: Add account with invalid fields
Given I am logged in as BudgetTest
And I am on the New Account page
When I fill in the form for account account_name with valid data
And I submit the data value1 for the field_type1 field,
field_name1
And I submit the data value2 for the field_type2 field,
field_name2
And I press Add Account
Then I should see the rendered template for the new account page
And I should see an error indicating field_name was error


I've removed the Scenarios:  blocks because they would wordwrap and look
terrible/undreadable.  Following this is two sets of scenarios:

Scenarios: missing required fields

Scenarios: submitting bad data

Some of the fields compare data with each other to determine validity
which is why there's two data entries in the scenario outline.  If the
second is left blank then the defaults that were set in When I fill in
the form... are used for it.  Each Scenarios block contains a table
with a of the fields defined by  in the outline.  As you can see,
it seems to me to be overly complicated, overly verbose, and perhaps
doing more than it should be.

I think maybe this test goes overboard...but what level of detail is
good for error-path testing?
  


Hi Nathan,
I think testing all of the validations from Cucumber is going 
overboard *unless* the customer wants to see them there.  I have done 
something like that but it was when I was writing my own validation 
logic (in this case I wasn't even using AR or another standard 
library). It was a nice way of showing the customer what were and were 
not valid values.  However, if you are using ActiveRecord to do 
standard validations then I see little value in checking each 
validation separately.  It will take a long time to run and it seems 
like it would really not add much value in terms of regression 
catching beyond what the fast model-level code examples would provide. 
So, like I said, the only value I would see in that would be for a 
customer to see that it is working as they want it to.


In general, I like to keep happy paths in Cucumber features along with 
some special error cases.  Driving though the entire stack is a 
double-edged sword.  It provides great regression testing and is an 
excellent way to frame scenarios for customers.  However, the number 
of execution paths you can execute from such a high level is 
inherently limited... the number of objects and all of there potential 
states in concert with one another results in a combinatorial 
explosion of number of test cases required to test everything.  That 
is why isolated specs on a lower level are still very valuable and for 
me provide a great deal of confidence when used along side some 
happy-path full-stack tests.  (And even then you can never test 
everything...)


Thats my current take on things at least... HTH,

Ben




BTW, please use the cucumber mailing list for cucumber related questions:

http://groups.google.com/group/cukes

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] On Mocks vs Stubs in the context of rSpec

2009-07-23 Thread Ben Mabey

Marcelo de Moraes Serpa wrote:

Hello list,

From what I could see, the lines between mocks and stubs are subtle,
but the general idea I got is that mocks set expectations and stubs
are only dummy objects/method calls. What confused me though, is that
the stub() method is an alias for mock() in
Spec::Mocks::ExampleMethods. So a stub is a mock?
  
Yes, no, and maybe so. :p  I agree with your general understanding that 
mocks set expectations and stubs are only dummy objects/method calls.  
The fact that rspec using the same machinery to provide stubs and mocks 
is really inconsequential because the deciding factor of what they are 
is how you use them.  You can, IMO, use a mock like a stub and a 
stub like a mock.. Take this for example:


describe #some_method do
 it delegates to some_obejct do
   some_object = stub('some object', :some_method = foo)
   my_object = MyObject.new(some_object)

   my_object.some_method.should == foo
 end
end

We are using a stub as a dummy object, and yet our expectation is 
clearing testing the method call.  So is the above a stub or is it 
really a mock?  I would say that it is acting like a mock.  I hope that 
others on the list will correct me if I am wrong making this 
observation/conclusion.   Likewise we could use a mock as a dummy object 
and never set any expectations on it and it would be acting like a 
stub.  Even though stub and mock is the same in RSpec you should still 
use the correct name when using them.



Also, another thing that is confusing: You have stub and stub! methods
in the Spec::Mocks::Methods namespace, what is the difference between
Spec::Mocks::ExampleMethods#stub and Spec::Mocks::Methods#stub ?
  


Spec::Mocks::ExampleMethods are the methods that you can call during the course of a code example.  
So when you say stub(something) the method in Spec::Mocks::ExampleMethods gets called 
and returns you a stub.  Now, that stub object now has it's own #stub method which lives on 
Spec::Mocks::Methods#stub.  That call will stub out the provided method and return value... So 
my_stub.stub(:foo, bar), however that is aliased from #stub! which is used most often.  
This is all from memory so I could be wrong but that is the general gist of it.


HTH,
-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] My very fist spec file (not sure what's wrong..)

2009-07-21 Thread Ben Mabey

internetchris wrote:

I have one additional question after thinking about this for a while.
Forgive me if I'm about to read this in the book, It came to mind so I
thought I would ask. When writing specs for controllers am I always
going to mock the model? Are controllers always isolated from the
actual model? If that's the case then using cucumber with webrat is
the only time I will test the complete stack right? Just wondering if
I understand this correctly.
  


When I am using Cucumber and writing controller specs that is always how 
*I* do it.  I like having the isolation for the controllers and keeping 
them fast.  Any integration problems will be exposed by Cucumber so I 
think having the controller specs test more that the controller is a 
waste in most cases.  This is just my opinion however.  People on this 
list will agree with me and disagree, so don't think that it is *the* 
way of doing things.  This is what the book recommends IIRC so you are 
understanding it.


-Ben


Thanks

Chris

On Jul 21, 9:25 am, internetchris ch...@silhouettesolutions.net
wrote:
  

Ben that worked perfectly I appreciate the help.

Stephen, I appreciate the encouragement, it feels daunting to be
learning all of this at once, but each day I bite off a little more
understanding.  It's funny you mention scuba diving - way back when
right out of high school I thought it would be fun to go to school for
underwater construction/welding - so I did. I suppose if I was able to
tackle that, I will eventually get this. I'm thankful I decided to
switch my degree path to computer science after that however. It was
an interesting part of my life to say the least. Maybe it's a
personality quirk of mine :-)

Thanks!

Chris

On Jul 20, 9:59 pm, Stephen Eley sfe...@gmail.com wrote:





On Mon, Jul 20, 2009 at 11:05 PM, Chris
  
Sundch...@silhouettesolutions.net wrote:
  

I am finally to the point in the rspec book where it describes how to
implement controller specs, so I thought what the heck, I'll give it a
try.


Heh.  Points to you for ambition!  You might not have realized this
(because the RSpec book makes it sound like it should *all* be easy)
but starting with a Rails controller spec for your very first spec is
a bit like saying I was thinking of getting scuba certified...
Ooooh, CAVE DIVING!  Let's start with that first!*
  
On the upside, if you start there and really get to *understand*

what's going on, you should be relieved when most of the rest of it is
pretty smooth sailing.  There are very few common Ruby idioms that
have such tight coupling as Rails controllers, so very few tasks are
so hard to spec in isolation.  You'll almost never have to mock
anything else as ferociously.  Model specs in particular will feel
like sunshine and puppies.
  
So go you!
  
--

Have Fun,  *(Granted, I don't think anyone has ever kicked up silt
while writing a controller spec, lost hold of their guide line, gotten
hopelessly lost, and died many hours later in the cold and dark.  Yet.
 That only happens to J2EE programmers.)
   Steve Eley (sfe...@gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
  

___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] My very fist spec file (not sure what's wrong..)

2009-07-20 Thread Ben Mabey

Chris Sund wrote:

Hey Everyone,

I am finally to the point in the rspec book where it describes how to
implement controller specs, so I thought what the heck, I'll give it a
try. I have an app I have been working on (Inside out) that I needed
to get test specs written for before I continue on with the app. Now
that I have read enough of the book I realize I was doing things a
little backwards in the rspec sense of BDD, but I thought I would
try to apply what I have learned so far to my existing code.

Here's the feedback I'm getting when I run my spec file

NoMethodError in 'AccountsController POST create should build a new
account'
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.save
/Users/Chris/Rails/obilling/app/controllers/accounts_controller.rb:
24:in `create'
./spec/controllers/accounts_controller_spec.rb:7:
script/spec:10:


Here's my spec file...

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper' )

describe AccountsController, POST create do

it should build a new account  do
  Account.should_receive(:new).with(address = 1201 washington
street)
  


This is your problem.. you need to return something for 'save' to be 
called on.  i.e.


 Account.should_receive(:new).with(address = 1201 washington
street).and_return(mock_model(Accrount))

Notice the and_return at the end?  That way a mock_model of Account will be 
returned from the new call so that the controller can set it to @account and save it.

To see some examples of RSpec controller specs you can use a generator to 
general rspec scaffolding... like so:

./script/generate rspec_scaffold Account

HTH,
Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [ANN] rspec 1.2.8 Released

2009-07-16 Thread Ben Mabey

David Chelimsky wrote:

rspec version 1.2.8 has been released!

* http://rspec.info
* http://rubyforge.org/projects/rspec
* http://github.com/dchelimsky/rspec/wikis
* rspec-users@rubyforge.org
* rspec-de...@rubyforge.org

Behaviour Driven Development for Ruby.

Changes:

### Version 1.2.8 / 2008-07-16

* enhancements
  * better messages for should[_not] be_nil (Chad Humphries and Rob Sanheim)
  * should and should_not accept optional custom message
(suggestion from Rob Sanheim)
  
Ahh, very nice.  I've been wanting something like this for a while.  For 
those interested in how to use this feature check out the examples in 
this cucumber feature for it:


http://github.com/dchelimsky/rspec/blob/1420b6f02f5fe2ba97286d895b8215617f80d4a6/features/matchers/define_matcher_with_user_customizable_message.feature

Thanks for the release.

-Ben


* result.should be_nil, expected result to be nil
  * added 'spec/stubs/cucumber' to plug RSpec's stubbing framework into
Cucumber scenarios.
  * added unstub method to remove a stub mid-example (Scott Taylor). Closes
#853.
  * add more readable diff when expected and actual are hashes (Ryan Bigg).
Closes #848.

* bug fixes
  * fixed --line option for ruby 1.9.1
  * fix stub_chain conflict between two chains starting with the same message
(Mike Rohland). Closes #846.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] ZenTest, RSpec and Ruby 1.9.1

2009-07-12 Thread Ben Mabey

Robert Rouse wrote:

Hello,

I thought maybe you guys could help. I'm trying to use RSpec along with
ZenTest.

However, all I seem to get back when trying to run tests is an
exception.

Is there a place I can find out what that exception is? I have autospec
set up to do the notifications through growl. The growl output only
tells me there was an exception.

I'd like to get it working.

Any ideas?
  



The output should be in the terminal window that you started autotest 
in What are you seeing exactly?  Please post your output.  Do you 
have the latest ZenTest and RSpec gems?  Also, are you using the 
autospec command that comes with RSpec?


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] loading custom matchers into cucumber

2009-07-08 Thread Ben Mabey

Joaquin Rivera Padron wrote:


hi there,
In a step I need to assert (don't know hoe to translate this into
should terms) state before keep going, example:


Perhaps you need to make an expectation instead of an assert?  :)




Given I have signed up as tom who is an admin do |user, role| do
# call some steps to create user tom

end


oops, sorry that was gone unfinished!

Given I have signed up as tom who is an admin do |user, role| do
# call some steps to create user tom
# I need to assert that tom really have the rol (this is not the 
most important, so please bear with me)

user_should_have_role user, role
end

that as you see is not very pretty, I would like to do:

Spec::Matchers.define :have_rol do |role|
  match do |user|
user.roles.collect{ |r| r.name http://r.name }.include?(role)
  end
end

and then assert:

tom.should have_role role

only I don't get to load the matcher. how you normally load custom 
machters to be used in cucumber?



Try putting your Spec::Matchers.define block in your env.rb file to see 
if that works.  I haven't looked closely at how the new matcher DSL adds 
the matchers but I would think that would work.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread Ben Mabey

Rick DeNatale wrote:

On Tue, Jul 7, 2009 at 11:35 AM, Chris
Sundch...@silhouettesolutions.net wrote:
  

Hey Everyone,

I've been working my way through the Rspec book trying to absorb and
understand everything. This is my first time with BDD and I'm just
trying to figure out some simple syntax stuff. My questions revolve
around some of the syntaxing used in the book. These are really simple
questions.


1.) Given /^the secret code is (. . . .)$/ do |code|
   Is (. . . .) simply a place holder? could I use something like
(- - - -) instead, or does it actually mean something?



Yes it actually means something. the stuff between // is a regular
expression, and some of the characters have meaning.

   ^ means the beginning of the string
   $ means the end of the string
   Each . will mark a single character, any character will do.
  The parens mark a group, the part of the string which marks the
group will be assigned to the code parameter.
  So when the whole regex matches code will be set to the four
characters of the code separated by spaces.
  

2.) Then /^the mark should be (.*)$/ do |mark|
   Similar questionwhat does .* represent?



it means zero or more arbitrary characters

  

3.) In the following example why don't I pass   |guess| to the When
statement? I'm sure it has something to do with the (code.split)
syntax, I'm just not sure what.

When /^I guess (. . . .)$/ do |code|
@game.guess(code.split)
end



There isn't a variable named guess here. As I said in answer to the
first question, if the story says

When I guess 1 3 4 2

then when the step is executed the code parameter to the block will be
set to 1 3 4 2 and 1 3 4 2.split gives [1, 3, 4, 2]
  

4.) And finally what does (\n) do?

Then /^the mark should be (.*)$/ do |mark|
 @messenger.string.split(\n).should include(mark)
end



\n is a ruby string literal representing a new-line, so
   @messenger.string.split(\n) results in an array comprising each
line within @messenger.string



  



Chris,
FYI, a good resource to learn and play around with reg exps in ruby is: 
http://rubular.com/


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Test doubles: expect x and don't care about anything else

2009-06-29 Thread Ben Mabey

Matt Wynne wrote:


On 28 Jun 2009, at 23:02, Wincent Colaiuta wrote:


El 28/6/2009, a las 23:04, Matt Wynne escribió:


On 28 Jun 2009, at 13:07, Wincent Colaiuta wrote:


I've had one of my recurring doubts about test doubles come up again.

The full post is here but I'll abbreviate the content in this 
message in any case:


https://wincent.com/blog/thinking-about-switching-to-rr

Basically, in one of my controller specs I wanted to verify that 
the following line was being called and doing the right thing:

@comment = Comment.find params[:id]
I had a mock for this set up, but it broke when unrelated code in 
the model was modified (a complex callback which itself called 
Comment.find).


I'd like to know more about how this happened. How did the model 
object's behaviour leak into the controller spec?


This was a spec for the controller's update action, which does a 
save on the record. At one point a change was made to the model to 
do some complex updates in the after_save callback, and these 
involved doing another Comment.find call, but with different parameters.


If I understand this correctly, there was only one call from 
Controller - Comment that you wanted to test; the other one was a 
call from Comment - Comment that happened as a side-effect.


So I'm wondering: if you'd returned a fake (mock, stub, whatever) 
comment from your stubbed Comment.find, would that have solved the 
problem?





In my ideal test-double framework, I'd like to really assert two 
things about the line of code in question:


1. That Comment.find gets called with a specific param at some 
point in time.
2. That the @comment instance variable gets the expected value 
assigned to it.


So why not use

Comment.stub!(:find).with(123).and_return(mock(Comment))


Because there are actually two find calls here:

- the one I actually care about
- the other one in the after_save callback which is irrelevant to the 
controller


I original used should_receive, not stub, so RSpec complained 
about getting find with the unexpected parameters. If I change to 
stub then I'm losing my assertion (no longer checking that the 
message gets sent), injecting a different return value (adding 
complexity), for no visible benefit (may as well just throw away the 
expectation).


What I often do is put a stub in first, which will work in all the 
examples, then put a should_receive in one of the examples if (as 
seems to be the case here) it's important to me to test the 
collaboration between the objects. So it would look like this:


describe #update do
  before(:each)
@comment = mock(Comment)
Comment.stub!(:find).and_return(@comment)
  end

  it should call the model to try and find the comment
Comment.should_receive(:find).with(123).and_return(@comment)
do_request
  end


You probably know this, but for the benefit of others... Pat made a 
change a while back that makes it so the stubbed return value will still 
be returned even if an expectation is added.  Meaning, assuming the stub 
is in the before block, you can change the expectation to:
   Comment.should_receive(:find).with(123)  # this will still return 
@comment


-Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Testing with activerecord at ThoughtWorks (Stubbing vs real DB)

2009-06-28 Thread Ben Mabey

oren wrote:

I am reading the post by Fowler, 'Ruby at ThoughtWorks'.
http://martinfowler.com/articl/rubyAtThoughtWorks.html#WasRubyTheRightChoice

He talks about testing with activerecord:

Right at the beginning of our use of Ruby, there was a debate on how
best to organize testing in the presence of the Active Record database
layer in Rails. The basic problem is that most of the time,
performance of enterprise applications is dominated by database
access. We've found that by using a Test Double we can greatly speed
up our tests. Having fast tests is crucial to our test-intensive
development process. Kent Beck recommends a basic commit build of
under ten minutes. Most of our projects manage this these days, and
using a database double is a vital part of achieving it.

The problem with Active Record is that by combining database access
code with business logic, it's rather harder to create a database
double. The Mingle team's reaction to this was to accept that Rails
binds the database tightly and thus run all the commit tests against a
real database.

The contrary view was advocated most firmly by the Atlanta and Jersey
teams. Ruby has a powerful feature that allows you to redefine methods
at run-time. You can use this to take an active record class, and
redefine the the database access methods in that class as stubs. The
team started the gem unitrecord to help with this.

In the three years, we've not seen a generally accepted victor in this
debate. The Mingle team run a couple of thousand tests against a real
postgres database in around 8 minutes. (They parallelize the tests to
make use of multiple cores.) The Atlanta and Jersey teams consider it
valuable that their commit test runs in 2 minutes with stubs versus 8
minutes without. The trade-off is the simplicity of the direct
database tests versus the faster commit build of the stubbed tests.

While both teams are broadly happy with their positions in this
debate, the use of stubbing has led to another issue for the Atlanta/
Jersey teams. As the teams became familiar with using method stubbing,
they used it more and more - falling into the inevitable over-usage
where unit tests would stub out every method other than the one being
tested. The problem here, as often with using doubles, is brittle
tests. As you change the behavior of the application, you also have to
change lots of doubles that are mimicking the old behavior. This over-
usage has led both teams to move away from stubbed unit tests and to
use more rails-style functional tests with direct database access.

What do you think of the two tactics?
  


I have done both on past projects.  I did not use any of the TW gems to 
do it.  I used Avdi Grimm's nice NullDB plugin to do it.  IMO it is a 
much better and cleaner approach than the ones talked about in the 
article.  I gave a lightning talk about the tradeoffs of both approaches 
and how I used NullDB in my project.  Here are the slides for the talk:

http://www.slideshare.net/bmabey/disconnecting-the-database-with-activerecord

The slides go through the benefits and tradeoffs of both approaches.  
Let me know if you want me to elaborate on anything else.  I should 
point out that another, but less extreme, solution to stubbing out the 
DB is to use an in-memory DB (like sqllite) to get a speed boost.  With 
this approach you may still need to switch to your real DB adapter for 
DB specific SQL but it all the basic AR stuff with work just fine.

Also, What does it mean and where can I see examples of running all
the commit tests against a real database ?
  


Sounds like they have configured there project to to allow you to hot 
swap which strategy to use.  So, for development you can use the 
stubbing approach and get faster feedback and then swap in the real 
database on the CI server to make sure there aren't any surprises when 
it is actually executed against the DB.  This is a good approach and can 
be done quite easily with NullDB.

Can I find it in the rspec book ?
  
I don't think so.  To be honest, I don't think it is done that much.  I 
think most teams just let there model tests hit the DB. (And thus are 
not real unit tests by some people's definition)



-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Integrate or isolate views?

2009-06-28 Thread Ben Mabey


On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote:


Hello,

I've been trying for two years to pick up BDD.  I'm making progress,
have just read through the chapters in The RSpec Book on spec'ing  
views

and controllers.

What is the difference between using integrate_views and doing what
seems to be a lot of extra work to test the views in isolation?

When I use integrate_views, can I write view spec in what would
otherwise be isolated controller spec?


Correct, by default RSpec's controller specs will not render the  
view.  This allows you to test the controller and view in complete  
isolation.  By turning on integrate_views you can specify what the  
rendered view should contain at the same time.  If you were to do  
outside-in dev starting from the view you would start out by writing  
an isolated view spec.  That spec would say that such and such would  
be displayed.  This would in turn prompt you to assign something to  
that view for it to be rendered.  That is then your signal that the  
controller needs to assign that object.  So, you go up a level and  
make sure that the controller action is assigning the needed object  
for the view.  That object will most likely have to answer to some  
methods used in the view so that prompts you to start writing examples  
on the model level.  Isolation has it's benefits, however an  
integration test (i.e. Cucumber scenario) is really needed to make  
sure these parts are all working together as expected.





I read that I'm encouraged to do these in isolation, but IMHO the
chapter on spec'ing views is not very convincing in its own right, it
tells me that it's good, but doesn't show me as much, compared to the
examples and descriptions of circumstance that make several other
chapters very convincing.


FWIW Jesse, you are not alone on this list in thinking that view specs  
are not that valuable.  A lot of people share your opinion, and I  
think Cucumber is generally used to specify the views the majority of  
the time.  This enables you to specify your controllers in isolation  
since your Cucumber features are cutting through the entire stack.  I  
personally think  view specs are a very nice tool to have available,  
but I would only use them on complex views.  By complex I don't mean  
riddled with logic, but a view that has a lot of stuff going on which  
is hard to set up all in one integration test (or Cucumber scenario).   
Since the majority of views are very simple then verifying them just  
in Cucumber is good enough, IMO.


-Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Integrate or isolate views?

2009-06-28 Thread Ben Mabey

Jesse Crockett wrote:

Ben Mabey wrote:
  

On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote:



When I use integrate_views, can I write view spec in what would
otherwise be isolated controller spec?
  

Correct, by default RSpec's controller specs will not render the
view.  This allows you to test the controller and view in complete
isolation.  By turning on integrate_views you can specify what the
rendered view should contain at the same time.  If you were to do
outside-in dev starting from the view you would start out by writing
an isolated view spec.  That spec would say that such and such would
be displayed.  This would in turn prompt you to assign something to
that view for it to be rendered.  That is then your signal that the
controller needs to assign that object.  So, you go up a level and
make sure that the controller action is assigning the needed object
for the view.  That object will most likely have to answer to some
methods used in the view so that prompts you to start writing examples
on the model level.  Isolation has it's benefits, however an
integration test (i.e. Cucumber scenario) is really needed to make
sure these parts are all working together as expected.



I read that I'm encouraged to do these in isolation, but IMHO the
chapter on spec'ing views is not very convincing in its own right, it
tells me that it's good, but doesn't show me as much, compared to the
examples and descriptions of circumstance that make several other
chapters very convincing.
  

FWIW Jesse, you are not alone on this list in thinking that view specs
are not that valuable.  A lot of people share your opinion, and I
think Cucumber is generally used to specify the views the majority of
the time.  This enables you to specify your controllers in isolation
since your Cucumber features are cutting through the entire stack. 



I gather that you are saying a balance of cucumber scenarios in tandem 
with spec'ing controllers and models in isolation is a reasonable 
conclusion and equally reasonable path to move forward?
  


Yes, IME this has worked well.
  

I personally think  view specs are a very nice tool to have available,
but I would only use them on complex views.  By complex I don't mean
riddled with logic, but a view that has a lot of stuff going on which
is hard to set up all in one integration test (or Cucumber scenario).
Since the majority of views are very simple then verifying them just
in Cucumber is good enough, IMO.

-Ben




I gather that you are affirming that adequate testing of controllers and 
models in isolation as presscribed the the Rspec Book can be 
accomplished without spec'ing the views in the same isolation, but 
instead by using 'integrate_views' with adequate cucumber scenarios?
  


The last part of your sentence is confusing me: but instead by using 
'integrate_views' with adequate cucumber scenarios?.  There is no 
integrate_views option in Cucumber as views are always rendered.  When 
I am using Cucumber I don't see the need to be using 'integrate_views' 
in my controller specs either. 

Keep in mind that I'm not affirming anything as a hard rule, but rather 
stating a guideline that I have gravitated towards in my past projects 
that were webapps.  You, like Sarah, may see enough value provided by 
view specs to warrant them.  I would encourage you to try them and then 
judge for yourself and the specific project you are working on.  If you 
don't get any value out of them then you can stop but you will at least 
know how to do it when a situation arises that seems better fit for them.


HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where to put macros

2009-06-22 Thread Ben Mabey


On Jun 22, 2009, at 10:37 AM, David Chelimsky wrote:

On Mon, Jun 22, 2009 at 11:28 AM, Andrew Premdasaprem...@gmail.com  
wrote:
Recently I got some wonderful help from the list to create my  
NamedAddress
module/macro which tests NamedAddresses for a number of different  
resources.
The question I have is where should I put this module? At the  
moment I've

got it in spec_helper, but this feels a bit messy
Many thanks
Andrew


The convention that I see emerging is to keep macros, helpers, and any
other spec supporting material in spec/support/macros,
spec/support/matchers, etc. Then you do this in spec/spec_helper.rb:

Dir[File.dirname(__FILE__) + /support/**/*.rb].each {|f| require f}

What would folks think if that was included in the generated
spec_helper in spec-rails?


Just as I said there was no written convention... :)

I like it.  +1

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] The problem with learning RSpec

2009-06-18 Thread Ben Mabey

Bill Kocik wrote:

Just to add a couple cents in...

I've been working as either a sysadmin or software developer for the
last 10 years (software development pretty much exclusively for the
last 5 or 6). I started picking up Rails about 2 years ago, and though
I was always aware of TDD - and even occasionally dabbled in it - I
never really embraced it. Not because I didn't see its importance, but
because the barrier to entry always seemed too high, and schedules
never allowed for it (as a friend of mine is fond of saying, You mean
we don't have time to do it right, but we have time to do it over and
over again?).

Right now I'm working on a personal project for which I have no QA
team to watch my back, so instead I'm doggedly using top-down BDD with
Cucumber (and unit tests) to help keep me in line. I think the biggest
hurdle to learning it is this: Pretty much all the tutorials and docs
written on the topic center around some simple example app that's easy
to test. But in the real world, software is messy, and tends to resist
being tested. I know the traditional counter argument is that this
means your design is flawed, but that isn't always true. One of the
biggest challenges I faced was how to test authentication in my
application, in which users sign in using their Twitter credentials
via OAuth[1]. Another was in testing my own endpoints that create JSON
that's rendered via JS in the browser[2]. Maybe Selenium could have
helped here, but creating tests in general was already slowing me to
the point that I'm a good deal behind schedule, and I couldn't take
another day or so to learn how to use Selenium with the risk that it
might not really suit my situation for one reason or another - because
software is messy.

One that I haven't tackled yet but will have to soon is how to test
code that runs as a BackgrounDRb worker.

I came up with solutions for all of this (except for the BDRb stuff),
but I'm not entirely sure of their quality. They certainly feel
hackish, but I can't put my finger on why. I suspect David Chelimsky
or Ben Mabey or Aslak or any of a hundred or more other people could
have come up with beautiful, elegant solutions
I'm flattered, but FWIW I am always struggling on how best to test 
things as well.  In cases like you are describing it seems like testing 
it is often harder than the actual implementation.  Making those tests 
valuable without being too brittle can be challenging.



 to the challenges I
faced, but since none of them were standing over my shoulder I have no
way of knowing, and none of this is covered in the
write-a-blog-in-10-minutes Rails demo.

That has been my challenge in learning and using BDD.
Thanks for sharing Bill.  I totally understand where you are coming 
from.  IME, it is hard when writing a tutorial or giving a presentation 
to not teach to the least common denominator in the audience (the 
beginner).  Time constraints usually set in too that don't allow you to 
do more advanced topics that would require more explanation.  Thats why 
for most presentations I try to focus more on the process and ideas 
rather than the example and tools (i.e stuff you can't learn from a wiki 
so easily).  I do see your point however.  I often feel frustrated in 
other presentations at the simplicity of examples given and wish for 
more in-depth and challenging examples.  Your point is noted: a good 
tutorial app for BDD should involve harder to test components (web 
services, asynchronous messaging/processing, caching, etc) since this is 
what pops up in real projects.


[1] My solution: http://tr.im/oW8y
  
This is more or less how I would of done this with Cucumber.  And you 
were complaining about no advanced tutorials. ;)  Nice writeup.



[2] I defined these two custom steps (JSON_CALLBACK is defined as the
:callback arg I pass in my 'render :json' calls - but it will trip the
JSON parser if its there):

Then /^I should get valid JSON$/ do
  assert_nothing_raised do
assert JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1'))
  end
end

Then /^I should find (.+) in JSON/ do |xpath|
  json_hash = JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1'))
  xmldoc = Nokogiri::XML(json_hash.to_xml)
  xpath.gsub!('_', '-') # in XML, underscores will be dashes.
  xpath = ./hash + xpath unless xpath =~ /^\/\//
  assert !xmldoc.xpath(xpath).blank?
end
  


I probably would of done this in RSpec instead of Cucumber.  Then I 
would manually tested in a browser.. since you are going to want to do 
that anyways.  I take this stance quite a bit as I feel adding Selenium 
(or another automated browser solution) can potentially add much more of 
a maintenance burden than webrat in :rails mode.


Thanks,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] shared examples sharing methods

2009-06-17 Thread Ben Mabey

David Chelimsky wrote:

On Wed, Jun 17, 2009 at 1:19 PM, Matt Wynnem...@mattwynne.net wrote:
  

On 17 Jun 2009, at 16:21, David Chelimsky wrote:



On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdasaprem...@gmail.com
wrote:
  

Please have a look at
http://gist.github.com/131277
What I'd like to do is create a shared_examples group which I can
parametize
a method. So my shared example would perhaps use method named_address=,
or
set_named_address and then groups that behave like Named address would
be
able to override this method so it sets the correct address e.g. the last
billing address


Here's the short version: There's been a lot of discussion on this
list about parameterizing shared examples. Basically, given the
current design it can't happen, and macros are a perfectly good
solution to the problem, so there's not much incentive to change the
design.
  

You can use instance variables to pass values to the shared examples,
though, right?



At your own risk, yes, of course :)
  


If you do go down that route, I recommend method calls instead of 
instance variables.  That way it will yell out you when you forget to 
define one. :)


-Ben
  

cheers,
Matt Wynne

http://mattwynne.net
+447974 430184

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] shared examples sharing methods

2009-06-17 Thread Ben Mabey

David Chelimsky wrote:

On Wed, Jun 17, 2009 at 10:14 AM, Andrew Premdasaprem...@gmail.com wrote:
  

Please have a look at
http://gist.github.com/131277
What I'd like to do is create a shared_examples group which I can parametize
a method. So my shared example would perhaps use method named_address=, or
set_named_address and then groups that behave like Named address would be
able to override this method so it sets the correct address e.g. the last
billing address



Here's the short version: There's been a lot of discussion on this
list about parameterizing shared examples. Basically, given the
current design it can't happen, and macros are a perfectly good
solution to the problem, so there's not much incentive to change the
design.

I'll try to follow up later with a recommendation about a macro,
unless somebody else beats me to it :)
  


I beat David to it. :)  Here are some options:

http://gist.github.com/131701

I think I like  #7 and #8 the best with the eval and #subject use.  With 
#8 I intentionally modify the backtrace so that the when errors happen 
it points to where the macro was called, not defined.  Sometimes this is 
desirable, YMMV.  FWIW, I question the value of such specs... but that 
is the macro approach.


-Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Spork and Merb and rSpec

2009-06-15 Thread Ben Mabey

Scott Taylor wrote:


On Jun 15, 2009, at 4:11 PM, Andy Shipman wrote:



On 15 Jun 2009, at 14:43, Scott Taylor wrote:


Andy Shipman wrote:
When running spork on a merb application, whenever a spec is run I 
get the following error from the Spork server.
/opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:1358: 
[BUG] rb_gc_mark(): unknown data type 0x3c(0x2203d0) non object

ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9]

Which crashes the Spork server.


Have you tried it on 1.8.6?


I have now and it works on 1.8.6. Thanks for the suggestion.


I'd suggest filing a bug on their tracker, wherever it may lie.

Scott



Spork uses github issues.  Also, FYI, spork has it's own mailing list: 
http://groups.google.com/group/sporkgem


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] The problem with learning RSpec

2009-06-13 Thread Ben Mabey

Stephen Eley wrote:

Ben and Rick,

Thanks very much to both of you for the encouraging responses.  Your
reply, Ben, came just in time as I was starting to wonder if I had
made a complete and irrevocable ass of myself.


On Fri, Jun 12, 2009 at 10:36 AM, Ben Mabeyb...@benmabey.com wrote:
  

In general though I don't know if I
really see all of this as a problem specific to RSpec.  The problem is that
many people coming to RSpec are not just RSpec novices but are in fact TDD
novices (and Rails, and Ruby novices too boot at times as well!).



FWIW, I agree totally.  In fact I re-read my message last night, and I
want to retract one of my statements for sure: the statement that
RSpec makes some easy things easy, but other easy things very
complicated.

On deeper thought, I don't believe this is true.  RSpec doesn't make
anything harder than it already is.  There's nothing _wrong_ with
RSpec in this sense.  I think a more incisive statement would be that
with RSpec, some complicated things _feel like they should be easier._
 If only because other things feel so easy.  And newbies tend to
confront those problem areas at a point in the growth curve where the
complexity can be misinterpreted as them Just Not Getting It.  Some
are driven off as a result.

You're right about practice.  You're right that bringing together too
many learning curves at once creates interference patterns that
shouldn't be blamed on RSpec.  And Rick's reference to Martin Fowler's
spiked learning curve -- this is scary, this is nifty, WHOOPS I
overdid it, this is okay in its place -- is an excellent point.

But I don't think it's totally out-of-bounds to frame it as an RSpec
problem, even if it isn't RSpec's fault.  The thing is...  Well...
There are *opportunities* here.  If RSpec -- along with its tools and
resources and culture -- was a little better at some of this stuff,
how much easier would it be to learn *everything else?*

How many of us learned BDD at the same time we learned programming?
...Show of hands?  Anyone?  The only developers who could make that
claim would have to be pretty fresh out of the pond.  If that does
apply to anyone reading this, please speak up -- I'd like to hear your
thoughts on how you're doing.

How many of us used TDD or BDD out of the gate when we learned Rails
or Ruby?  This is plausible, but I get the sense it's uncommon.  Most
of us don't even think to work on good testing practices until we
believe we're getting the rest of the stuff down.  I know I didn't.
  


When learning a new technology I generally don't bother with testing let 
alone TDD (unless I think TDD could help the learning process).   It is 
like spiking and most of the stuff you are creating is throw-away code 
that won't need to be maintained.  There are times, like this, where 
testing isn't needed IMO.  But that isn't really your question is it.. 
You're wondering what effect teaching good testing practices up front 
would bring...  I've wondered this my self at times (in fact I'm helping 
prepare an intro rails course now and wresting with this very issue) and 
it seems like teaching good testing to people who don't even know OO can 
be like jumping in to the deep end of the pool.



Formal education in programming doesn't help.  Not by any evidence to
my eyes.  I've recently started seeing someone who's majoring in CS at
a well-known university, and he said the first class he took on
software design was in C.  Frickin' *C*.  _Then_ they did C++, and
then Java, but there was nothing significant about testing.  I told
him about Cucumber and it made his heart go pitter-patter.
  


I hear this complaint quite often and FWIW it is an untrue stereotype 
IME.  While I was at the university I was taught testing, design 
patterns, refactoring, Agile methodologies, pair programming, use cases, 
CI, etc...  In fact the first time I heard about TDD was in my first 
Java class where the professor would TDD all of his work in the lectures 
(live coding!).  We did team projects where we had a CI server setup and 
we were required to have tests and do pair programming at least part of 
the time.  We also had class projects where different teams would create 
different components and we had to work out our communication protocols, 
touch points, and integrate it all.  Anyways, I justed wanted to throw 
that out and say that formal education isn't totally failing like some 
people claim it is.  Only my Software Engineering courses taught and 
encouraged these practices, but I was still taught them.



The teaching resources for Rails and Ruby don't help.  Just about
every book makes a *nod* toward testing -- there's always a chapter,
they always say do this constantly -- but the chapter's inevitably
somewhere near the back, after everything else has been introduced.
Rails culture is passionate about testing, but most of us don't start
to tap into that culture until we're at 'Competent' or above.

What if the world were different?  What 

Re: [rspec-users] The problem with learning RSpec

2009-06-12 Thread Ben Mabey



I'm rambling now, and I've spent *way* too much of my workday on this
message, so I'll just summarize:

* Some easy things are complicated in RSpec;
* Incomplete understanding of RSpec and a framework being spec'ed can
create learning deadlock;
* Novices need different answers than competent practitioners;
* The community as a whole should be aware and respectful of the
growth curve difficulty.

If anyone had the patience to read this far, any thoughts?  Am I
identifying real issues, or am I just full of hot air?


  




Hi Stephen,
I did in fact read your entire message, but I'm running out of time so 
I'm afraid I can't reply with the thoughtful response that it deserves.  
Here is my brief gut reaction.. I totally agree about your observation 
WRT the Dreyfus model.  I've thought about how how it relates to TDD/BDD 
in the past and have made similar conclusions.  I think you are spot on 
about an expert not being able to really answer a novice's question very 
well.. because they are suffering from the curse of knowledge and it 
is hard to remember what it was like without all that knowledge. 
In general though I don't know if I really see all of this as a problem 
specific to RSpec.  The problem is that many people coming to RSpec are 
not just RSpec novices but are in fact TDD novices (and Rails, and Ruby 
novices too boot at times as well!).   TDD, like you said, is a skill 
apart from programming and is really separate from learning the 
mechanics of RSpec.  A well practiced TDDer without much Ruby experience 
is in a much better position to use RSpec effectively than an 
experienced Ruby dev with no TDD experience.  So if the real problem is 
that people don't know TDD/BDD I think outside of the RSpec community 
there are a lot of resources to draw on.  There are great TDD books in 
addition to lists dedicated to TDD, presentations on TDD, etc...  
Perhaps one step would be to link to these resources?  I also agree with 
Rick in that it just takes experience to learn this stuff since the 
answers to questions are so context specific.  Anyways, I gotta run, but 
I those were some of the thoughts I had.


Thanks,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Given/When/Then blocks on Cucumber

2009-06-05 Thread Ben Mabey

Maurício Linhares wrote:

Hello guys,

I've been looking at Pyccuracy and found the Given/Then/When blocks
to be very interesting and easier to understand and write, specially
when writting scenarios with more than one of those. An example can be
found here: http://www.pyccuracy.org/getting_started_3.html

Here's how they do:

Scenario 1 - Searching for Hello World
Given
  I go to http://www.google.com;
When
  I fill q textbox with Hello World
  And I click btnG button
Then
  I see Hello World - Google Search title

And here's how we would do with Cucumber

Scenario: Searching for Hello World
  Given I go to http://www.google.com;
  When  I fill q textbox with Hello World
  When  I click btnG button
  Then I see Hello World - Google Search title

With cucumber we need to repeat the When's, Then's and Given's if
there's more than one, woudn't it be nice to avoid this?
  


Yep, and you can... (since Cucumber started you've been able to do this)

You can use And and But:

Scenario: Searching for Hello World
 Given I go to http://www.google.com;
 When  I fill q textbox with Hello World
 And  I click btnG button
 Then I see Hello World - Google Search title
 But I should not see Whatever


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Given/When/Then blocks on Cucumber

2009-06-05 Thread Ben Mabey

Maurício Linhares wrote:

Hello guys,

I've been looking at Pyccuracy and found the Given/Then/When blocks
to be very interesting and easier to understand and write, specially
when writting scenarios with more than one of those. An example can be
found here: http://www.pyccuracy.org/getting_started_3.html

Here's how they do:

Scenario 1 - Searching for Hello World
Given
  I go to http://www.google.com;
When
  I fill q textbox with Hello World
  And I click btnG button
Then
  I see Hello World - Google Search title

And here's how we would do with Cucumber

Scenario: Searching for Hello World
  Given I go to http://www.google.com;
  When  I fill q textbox with Hello World
  When  I click btnG button
  Then I see Hello World - Google Search title

With cucumber we need to repeat the When's, Then's and Given's if
there's more than one, woudn't it be nice to avoid this?

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) |
http://codeshooter.wordpress.com/ (en)
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


BTW, please use the new Cucumber ML for cucumber related posts:

http://groups.google.com/group/cukes

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Disabling cucumber for autotest

2009-05-28 Thread Ben Mabey

Ben Johnson wrote:

Hi,

For some reason, no matter what, my entire cucumber suite is ran after 
every auto test. Is there a way to make auto test ignore cucumber all 
together?


Thanks for your help.



Hi Ben,
The default behaviour is for it to not run the features at all.  In fact 
Cucumber will not even hook into autotest unless you have an environment 
variable called AUTOFEATURE set to true... Want to check to see if you 
have exported that variable?  If that env var is not set then I'm at a 
loss on why autotest would be picking up cucumber's autotest plugin... 
BTW, cucumber has it's own mailing list now: 
http://groups.google.com/group/cukes


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucmber Step to insert Test Data into Database

2009-05-27 Thread Ben Mabey

Scott Taylor wrote:

David Chelimsky wrote:
On Wed, May 27, 2009 at 5:20 AM, Smita Sreekanth 
li...@ruby-forum.com wrote:
 

Hi,

We run the feature created for a form to identify the fields and 
also to

add data into the respective fields.

But while running the cucumber features, all the scenario and steps are
getting passed but the record is not getting inserted into the
application / the database.

We have also wrote the feature as:

Feature: Adding a user
 In order to add a user to the organization
 As a administrator
 I want to create and add new user

Scenario: Create User
 Given that I have no users
 And I am on the List of users
 When I follow New User
 And I fill in First Name with Rebecca
 And I fill in Second Name with Martin
 And I fill in Title with Miss
 And I fill in Email with rebeccamar...@me.com
 And I fill in Telephone with 01617867645
 And I fill in Mobile with 01777867645
 And I fill in Fax with 01617867640Î
 And I fill in Address Line 1 with 58
 And I fill in Address Line 2 with West Tree rd
 And I fill in Address Line 3 with Stockport
 And I fill in County with Cheshire
 And I fill in Country with United Kingdom
 And I fill in Zip Code with sk8 4ty
 And I press Create
 Then I should have 1 user


And steps as:

Then /^I should have ([0-9]+) user$/ do |c|
 User.count.should==c.to_i
end

Given /^that I have no users$/ do
 User.delete_all
end

If somebody could help us out, how to execute the steps so that the 
data

gets inserted into the database.

Smita.



Hi Smita. Please use the new Cucumber google group for new threads
about Cucumber:

  http://groups.google.com/group/cukes
  


When was the decision made to split off the cucumber group?

Scott


http://rubyforge.org/pipermail/rspec-users/2009-May/014502.html

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] spec_server errors when reloading fixture replacement pl

2009-05-26 Thread Ben Mabey

Scott Taylor wrote:


On May 26, 2009, at 1:22 PM, Mark Wilden wrote:

On Sun, May 24, 2009 at 10:17 PM, Ben Mabey b...@benmabey.com 
mailto:b...@benmabey.com wrote:



Well, so Spork was really created with testing in mind.  It is
more general purpose than spec_server though.  You can use it
with any Ruby project, not just Rails.  You can also potentially
use it with any other testing framework that adds support for it
(I've been meaning to do this for Cucumber).  I know that Tim's
original work with Kernel.fork was actually dealing with Mongrel
but I'm not sure what the exact details of it are.  I'll try to
find out for you though.


Spork seems to have the same problem that I have with spec_server: it 
doesn't reload classes I change. So if I'm doing TDD between a model 
and its spec, it doesn't help.


I noticed the same thing.  It must be a bug in spork, correct?

Scott


What does your spec_helper look like?

It should be something like:

require 'rubygems'
require 'spork'

Spork.prefork do
 ENV[RAILS_ENV] = test
 require File.expand_path(File.dirname(__FILE__) + 
/../config/environment)
 # Load other stuff that only needs to be setup once and never reloaded 
(i.e. rspec and configuring it)

end

Spork.each_run do
 ActiveRecord::Base.establish_connection # make sure that the db 
connection is ready.
 require File.expand_path(RAILS_ROOT + /spec/fixjour_builders.rb) # 
You could use FixtureReplacement, FactorGirl, etc...


 Spec::Runner.configure do |config|
   config.include Fixjour
   include SharedSpecHelpers
   include DatabaseHelpers
   include AuthenticatedTestHelper

 end
end



Keep in mind that the code in Spork.prefork must not require any of your 
models inadvertently.  If your environment file does this or a plugin 
does then your models will not be reloaded.  Look over your spec_helper 
file and try to see who is requiring your models initially. We have 
really only tested this on is our apps where Tim and I work... So, there 
could very well be bugs we need to iron out.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] spec_server errors when reloading fixture replacement pl

2009-05-26 Thread Ben Mabey

Scott Taylor wrote:


On May 26, 2009, at 2:31 PM, Ben Mabey wrote:


Scott Taylor wrote:


On May 26, 2009, at 1:22 PM, Mark Wilden wrote:

On Sun, May 24, 2009 at 10:17 PM, Ben Mabey b...@benmabey.com 
mailto:b...@benmabey.com wrote:



   Well, so Spork was really created with testing in mind.  It is
   more general purpose than spec_server though.  You can use it
   with any Ruby project, not just Rails.  You can also potentially
   use it with any other testing framework that adds support for it
   (I've been meaning to do this for Cucumber).  I know that Tim's
   original work with Kernel.fork was actually dealing with Mongrel
   but I'm not sure what the exact details of it are.  I'll try to
   find out for you though.


Spork seems to have the same problem that I have with spec_server: 
it doesn't reload classes I change. So if I'm doing TDD between a 
model and its spec, it doesn't help.


I noticed the same thing.  It must be a bug in spork, correct?

Scott


What does your spec_helper look like?

It should be something like:

require 'rubygems'
require 'spork'

Spork.prefork do
ENV[RAILS_ENV] = test
require File.expand_path(File.dirname(__FILE__) + 
/../config/environment)
# Load other stuff that only needs to be setup once and never 
reloaded (i.e. rspec and configuring it)

end

Spork.each_run do
ActiveRecord::Base.establish_connection # make sure that the db 
connection is ready.
require File.expand_path(RAILS_ROOT + /spec/fixjour_builders.rb) # 
You could use FixtureReplacement, FactorGirl, etc...

Spec::Runner.configure do |config|
  config.include Fixjour
  include SharedSpecHelpers
  include DatabaseHelpers
  include AuthenticatedTestHelper
end
end



Keep in mind that the code in Spork.prefork must not require any of 
your models inadvertently.  If your environment file does this or a 
plugin does then your models will not be reloaded.  Look over your 
spec_helper file and try to see who is requiring your models 
initially. We have really only tested this on is our apps where Tim 
and I work... So, there could very well be bugs we need to iron out.


Sweet!  Seems to be working great now.

Looks like the README has changed over the weekend - previously, I had 
been starting the spec server with script/spec_server.  Running spork 
directly seems to work just fine.


Thanks a TON!

Scott




Ok cool.  Seems like the bug may of been poor documentation... please 
send a pull request if you think it can be improved.  :)


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] spec_server errors when reloading fixture replacement pl

2009-05-24 Thread Ben Mabey

Scott Taylor wrote:

Ben Mabey wrote:

Scott Taylor wrote:

Ben Johnson wrote:
Did anyone ever figure out the factory_girl / machinist issues? I 
am having the same problems and can figure out how to fix it for 
the life of me. The first run works fine, then afterwards I get a 
bunch of these errors:


No blueprint for class Venue

Any ideas? Thanks!
  
I don't know about Machinist or Factory Girl.  Basically, here's the 
deal:


If those libraries use require instead of load, you are screwed.  
Same goes for autoload'ing.
Yep.  You might want to check out Spork[1].  It is a drop-in 
replacement for spec_server that uses Kernel.fork instead of 
reloading classes to ensure a clean app state.  My coworker, Tim 
Harper, wrote it and it has been working great for us so far.   
(There is a little setup, so not quite drop-in but it just works with 
the --drb flag for rspec.)


1. http://github.com/timcharper/spork/tree/master

-Ben


That's absolutely awesome.
Have there been any attempts to generalize this, so that mongrel will 
fork on each request (a la shotgun)?  (I'm still stuck on rails 2.0.2, 
so a non-rack based reloading scheme would be great).


Well, so Spork was really created with testing in mind.  It is more 
general purpose than spec_server though.  You can use it with any Ruby 
project, not just Rails.  You can also potentially use it with any other 
testing framework that adds support for it (I've been meaning to do this 
for Cucumber).  I know that Tim's original work with Kernel.fork was 
actually dealing with Mongrel but I'm not sure what the exact details of 
it are.  I'll try to find out for you though.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] spec_server errors when reloading fixture replacement pl

2009-05-23 Thread Ben Mabey

Scott Taylor wrote:

Ben Johnson wrote:
Did anyone ever figure out the factory_girl / machinist issues? I am 
having the same problems and can figure out how to fix it for the 
life of me. The first run works fine, then afterwards I get a bunch 
of these errors:


No blueprint for class Venue

Any ideas? Thanks!
  
I don't know about Machinist or Factory Girl.  Basically, here's the 
deal:


If those libraries use require instead of load, you are screwed.  Same 
goes for autoload'ing.
Yep.  You might want to check out Spork[1].  It is a drop-in replacement 
for spec_server that uses Kernel.fork instead of reloading classes to 
ensure a clean app state.  My coworker, Tim Harper, wrote it and it has 
been working great for us so far.   (There is a little setup, so not 
quite drop-in but it just works with the --drb flag for rspec.)


1. http://github.com/timcharper/spork/tree/master

-Ben




If those libraries internally use load, or load_dependency, and you 
have cache_classes = false in your dev env, you could try manually 
reloading it.
Here's FixtureReplacement in script/console (@ version 2.1) after 
reload! is called:


http://gist.github.com/116422
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber: Running one feature under one profile

2009-05-22 Thread Ben Mabey

aslak hellesoy wrote:

Hey Folks,




Aargh profiles. The initial intention was that you could just do
cucumber -p foo.
And then you wouldn't have to type a lot of arguments.

The intention was *not* to use -p along with additional arguments,
although cucumber lets you do it by merging stuff together.

Using profiles as a mechanism to run various subsets of features and
step definitions that live underneath the same features directory is
something I do *not* recommend. It's much easier to have several
different root folders:

features # regular stuff
selenium_features # only selenium stuff

And a rake task for each. Or run cucumber selenium_features or
cucumber features as you see fit.

I know the wiki recommends all this crazy profile stuff. I'm sorry
about that - I didn't write it.
  


I somewhat disagree, the combination of profiles + tags is a good way to 
organize the features IMO.  The feature file talks about the feature 
regardless of if it uses JS or not.  So, if you have a feature that uses 
webrat 90% of the time but then has one or two scenarios that require JS 
you don't need to split that feature into two separate features files- 
you can just tag them.   I can see how having separate dirs can be 
helpful as well, but in general I kinda like the crazy profile stuff. :)


FWIW,

Ben

  

I followed the instructions on 
http://wiki.github.com/aslakhellesoy/cucumber/setting-up-selenium
and created 2 profiles: default and selenium. It works, but not if I
want to run one feature under a specifc profile. For example, I tried:

cucumber -p default --require features features/plain/
manage_users.feature

and I get all the tests including the selenium server.

What's goin' on like?



Try to add --verbose to see what's going on. Or better - organise your
features like I described above, and lose the profiles.

Aslak

  

Thanks
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber vs Rails Fixtures

2009-05-20 Thread Ben Mabey

Phlip wrote:

Cucumberists:


FYI, Cucumber now has it's own mailing list: 
http://groups.google.com/group/cukes


Apologies for not jumping into some wild alternate fixture (or mock!) 
system, but the unit tests at my new day gig are cough hanging by a 
thread as it is.


I need to show off some cute Cuke, _without_ rocking the boat!

How do I actually use real, pre-existing Rails fixtures, the same as 
the unit tests use? For familiarity?


http://wiki.github.com/aslakhellesoy/cucumber/fixtures


-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Change cache_classes on the fly?

2009-05-20 Thread Ben Mabey

tatyree wrote:

Strange request, I know...also seems pretty unlikely that it will
work, but:

Any thoughts on how I might change the setting on the fly (or stub
it)?  I'm stopping certain classes loading in production, and I'd like
to be able to test the behavior without having to manually change the
setting in test.rb.

Thanks,
Todd

  
Try changing the Rails.configuration.cache_classes setting at the 
appropriate times...


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] Fail a scenario from After or AfterStep

2009-05-19 Thread Ben Mabey

Luke Melia wrote:
Any further thoughts on this, Aslak? I'd prefer to go with a solution 
in line with the future direction of Cucumber if possible.


Cheers,
Luke


Have you seen what Matt added recently?

https://rspec.lighthouseapp.com/projects/16211/tickets/330-gracefully-handle-exceptions-in-after-block#ticket-330-11

I think this should cover your use case... WDYT?

-Ben



On May 15, 2009, at 5:12 PM, Luke Melia wrote:


On May 15, 2009, at 3:36 PM, aslak hellesoy wrote:


Thanks for doing that. I have one more favour to ask: Can you show me
an example of a StepDefinition that would cause the file to be
created?


That is a tougher question, because any browser interaction that 
causes an HTTP request to the app under test could result in a server 
error.


Ajax requests can be triggered by javascript, and in various parts of 
our app, they are triggered by clicking on links, submitting forms, 
dragging and dropping divs, hovering over a div, waiting for a page 
load to complete, as a callback from interacting with a 3rd party web 
service, or waiting for a setTimeout to execute.


So one way I could tackle it is to add a step to the end of every 
scenario that says Then the application should not have issued any 
responses with 50x status codes, but that would be a) repetitive, 
and b) not fail until all steps had run, making it harder to track 
down the step in the test where the failure occurred.


One way to look at may be that I'm trying to enforce an invariant. 
Under no circumstances in my test suite is it appropriate for my app 
to raise a 50x error. In my Rails integration suite, webrat enforces 
this particular invariant for me, but can't find a good hook in the 
selenium test stack to do this, which is why I'm looking at this route.


Cheers,
Luke

--
Luke Melia
l...@lukemelia.com
http://www.lukemelia.com/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


--
Luke Melia
l...@lukemelia.com
http://www.lukemelia.com/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] autotest?

2009-05-19 Thread Ben Mabey

Denis Haskin wrote:
Can someone point me to some decent doc on autotest?  Everything I'm 
finding seems either pretty old, or says autotest and rspec work out 
of the box, which it isn't for me...


I installed the grosser-autotest gem (just guessing) and when I run 
autotest it only runs (legacy) test/unit tests.


Suggestions?
RSpec now ships with an autospec command that acts as a wrapper.. are 
you using it?


-Ben


Thanks...

dwh



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] Fail a scenario from After or AfterStep

2009-05-19 Thread Ben Mabey

Ben Mabey wrote:

Luke Melia wrote:
Any further thoughts on this, Aslak? I'd prefer to go with a solution 
in line with the future direction of Cucumber if possible.


Cheers,
Luke


Have you seen what Matt added recently?

https://rspec.lighthouseapp.com/projects/16211/tickets/330-gracefully-handle-exceptions-in-after-block#ticket-330-11 



I think this should cover your use case... WDYT?

-Ben



Never mind, I just reread the thread...  :)


On May 15, 2009, at 5:12 PM, Luke Melia wrote:


On May 15, 2009, at 3:36 PM, aslak hellesoy wrote:


Thanks for doing that. I have one more favour to ask: Can you show me
an example of a StepDefinition that would cause the file to be
created?


That is a tougher question, because any browser interaction that 
causes an HTTP request to the app under test could result in a 
server error.


Ajax requests can be triggered by javascript, and in various parts 
of our app, they are triggered by clicking on links, submitting 
forms, dragging and dropping divs, hovering over a div, waiting for 
a page load to complete, as a callback from interacting with a 3rd 
party web service, or waiting for a setTimeout to execute.


So one way I could tackle it is to add a step to the end of every 
scenario that says Then the application should not have issued any 
responses with 50x status codes, but that would be a) repetitive, 
and b) not fail until all steps had run, making it harder to track 
down the step in the test where the failure occurred.


One way to look at may be that I'm trying to enforce an invariant. 
Under no circumstances in my test suite is it appropriate for my app 
to raise a 50x error. In my Rails integration suite, webrat enforces 
this particular invariant for me, but can't find a good hook in the 
selenium test stack to do this, which is why I'm looking at this route.


Cheers,
Luke

--
Luke Melia
l...@lukemelia.com
http://www.lukemelia.com/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


--
Luke Melia
l...@lukemelia.com
http://www.lukemelia.com/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber rake/webrat issue.

2009-05-18 Thread Ben Mabey

Matthew Van Horn wrote:
I'm probably missing something really obvious, but I just upgraded 
cucumber, rspec/rails, and webrat on a project, and for some reason, 
cucumber is not seeing any of the webrat steps (or bmabey's email 
steps) when running from rake.  It seems ok when running using the cucumb



Did you read the History on how to upgrade?  If not see if it helps.. 
here is the pertinent info:


** IMPORTANT UPGRADE NOTES FOR RAILS USERS **

Running Cucumber features in the same Ruby interpreter as Rake doesn't 
seem to work,
so you have to explicitly tell the task to fork (like it was doing by 
default in prior

versions). In lib/tasks/cucumber.rake:

 Cucumber::Rake::Task.new(:features) do |t|
   t.fork = true # Explicitly fork
   t.cucumber_opts = %w{--format pretty}
 end

(If you run script/generate cucumber this will be done for you).
Alternatively you can omit forking and run features like this:

 RAILS_ENV=test rake features

However, setting the RAILS_ENV is easy to forget, so I don't recommend 
relying on this.



-Ben


The versions are (most recent of the following):
bmabey-email_spec (0.1.3)
cucumber (0.3.5, 0.3.2, 0.3.0)
rspec (1.2.6, 1.2.4)
rspec-rails (1.2.6, 1.2.4)
webrat (0.4.4)

My env.rb looks like this:

# Sets up the Rails environment for Cucumber
ENV[RAILS_ENV] ||= test
require File.expand_path(File.dirname(__FILE__) + 
'/../../config/environment')

require 'cucumber/rails/world'
require 'email_spec/cucumber'

require 'cucumber/formatter/unicode' # Comment out this line if you 
don't want Cucumber Unicode support

Cucumber::Rails.use_transactional_fixtures
Cucumber::Rails.bypass_rescue # Comment out this line if you want 
Rails own error handling
  # (e.g. rescue_action_in_public / 
rescue_responses / rescue_from)


require 'webrat'

Webrat.configure do |config|
  config.mode = :rails
end

require 'cucumber/rails/rspec'
require 'webrat/core/matchers'


Lib tasks cucumber.rake looks like:
$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if 
File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')


begin
  require 'cucumber/rake/task'

  Cucumber::Rake::Task.new(:features) do |t|
t.fork = true
t.cucumber_opts = %w{--format pretty}
  end
  task :features = 'db:test:prepare'
rescue LoadError
  desc 'Cucumber rake task not available'
  task :features do
abort 'Cucumber rake task is not available. Be sure to install 
cucumber as a gem or plugin'

  end
end

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Rails HTML error page in the console.

2009-05-13 Thread Ben Mabey

Matt Wynne wrote:
I'm still bugged by the fact that when I get an exception during a 
feature run (e.g. Couldn't find partial) then what I see in the 
console is all the HTML to report that error in a browser.


I have had a few ideas for this bubbling around at the back of my 
mind. I wondered whether anyone else was thinking about this too.


I guess the idea would be to patch rails's 
ActionController#rescue_action_locally with something that threw the 
exception out at Cucumber rather than bubbling it up to the web. What 
do you think? Would it work? What are the drawbacks I haven't thought of?


cheers,
Matt Wynne
http://beta.songkick.com
http://blog.mattwynne.net



Have you tried catching the error in an After block and opening up the 
page?  Aslak added that functionality:


https://rspec.lighthouseapp.com/projects/16211/tickets/272-pick-up-failure-on-after-hook

-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Test JSON with Cucumber

2009-05-11 Thread Ben Mabey

Bill Kocik wrote:

Hi Folks -

I'm hoping someone has come before me in trying to do this. I want to
use Cucumber to acceptance-test my JSON output. So far all I can do is
validate that the JSON is valid, with this step:

Then /^I should get valid JSON$/ do
  assert_nothing_raised do
ActiveSupport::JSON.decode(@response.body)
  end

What I'd really like to do is be able to drill down into the JSON
looking for the presence of certain elements in their correct places.
For example, if my JSON is {foo:{bar:baz}} and parses out to
{'foo' = {'bar' = 'baz'}} then I want to be able to test that
['foo']['bar'] gives me 'baz', or at least that ['foo']['bar'] exists.
Unfortunately I'm not sure how to go about writing step definitions to
do anything like this, since I haven't yet figured out a way to take a
regular expression or string and inspect a hash with it.

Anyone have any ideas? I could really use a brain-kick here.

Thanks...

  


Well.. IIRC ActiveSupport::JSON.decode will return a ruby hash of the 
JSON, correct?  So you should be able to make expectations on it just 
like a regular hash object.


json = ActiveSupport::JSON.decode(@response.body)
json['foo']['bar'].should == 'baz'.


Does that help or am I missing something about your question?

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber 0.3.3 - Examples:

2009-05-11 Thread Ben Mabey

James Byrne wrote:

Am I correct when I infer that the Examples keyword is now only valid
in a Scenario Outline?  If so, in what version did this change take
place?
  



Yes... Examples is only valid in Scenario Outlines, but you can also 
use Scenarios as well.  I don't remember being able to use Examples 
outside of the of Scenario Outlines.  Where were you using it before?  
My guess is that if you were using it before it was an unintentional 
feature that was removed when things were cleaned up.  Aslak or Joesph 
could give you a more definitive answer.  In short, I don't know what 
version this change happened in- sorry.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Running single spec files -- how?

2009-05-11 Thread Ben Mabey

court3nay wrote:

Before upgrading from 1.1.11 to 1.2.4 I used to be able to do this:

  ruby spec/models/user_spec.rb

Now it looks like you have to do

  script/spec spec/models/user_spec.rb

Or something like this, which is actually kinda cool:

  script/spec spec/*/user*

Is that correct? Am I missing something?
  


There was a change that broke this behaviour, but it was documented in 
the History and how to get back the old behaviour:


=== Version 1.2.0 / 2009-03-15

* warnings:

 * If you use the ruby command to run specs instead of the spec 
command, you'll
   need to require 'spec/autorun' or they won't run. This won't affect 
you if
   you use the spec command or the Spec::Rake::SpecTask that ships with 
RSpec.




So... just add a require 'spec/autorun' in your spec_helper.rb and you 
should be good to go.


HTH,

Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [cucumber] how to debug cucumber with netbeans?

2009-05-09 Thread Ben Mabey

Jean-Michel Garnier wrote:


Jean-Michel Garnier wrote:
  

3 months ago, I submitted a patch to cucumber so I could run cucumber from
a
ruby script and use the debugger in netbeans
(https://rspec.lighthouseapp.com/projects/16211/tickets/128-running-feature-from-ruby-script)

It worked well at the time but I can't make it work with cucumber 0.3.2.
Here is the stacktrace:
Cucumber::Netbeans::Runner.new().run_feature
features/_admin/projects.feature

I wonder if fellow netbeans on cucumber users will have an idea ...
Ironically, debugging that script with netbeans crashes the debugger at
Library/Ruby/Gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54 


For the time being, I am using the old school ruby-debug which works
pretty well ...

JM
  



Thanks for your answer, Ben

  
So, you can run the feature fine without the debugger?  



* yes, it run fine indeed, I mean it loads everything all right and then
crash in a cucumber step with  segmentation fault

  
What is 
confusing is that lib/active_merchant is showing up in the backtrace 
saying it can't be found... 



* I don' understand it either and I suspect it's a Rails / cucumber /
polyglot rubygems issue as I have found a few messages describing problems
with cucumber and polyglot_original_require'
 from /Library/Ruby/Gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54

* For the time being, I just give up debugging cucumber with netbeans ...

  
What if you try to run the feature with the 
debugger from outside of Netbeans?  



* You mean with classic ruby-debug? I had never used it before as I come
from a java + Eclispe background and always used an IDE to debug. 


I must admit that ruby-debug is very easy to use and it did well to find the
cause of my problem:
cucumber calling webrat visit with eval. There was a bug in a
before_filter of a controller which was doing an infinite loop. Apparently,
the mac ruby interpreter did not like it and crashed with segmentation
fault. Running Rails in development mode was working fine and showing an
exception stacktrace... 


This is the kind of situtation where TDD is actually slower than
prehistoric development with no tests. I spent 3 hours looking for the
source of the problems and it took me 15 minutes running Rails in
developement mode. 


In order to improve webrat, I'll spend 1 hour this morning o try to write a
spec to reproduce the bug.
  
Glad you got it fixed.  Yeah, TDD/BDD certainly can slow you down at 
times especially on initial investments like this.  It just comes down 
to if it is worth it for you and this project or if you would be fine 
with some technical debt. :)


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Problem verifying routing error

2009-05-08 Thread Ben Mabey

Randy Harmon wrote:

Hi,

When upgrading to rspec/rspec-rails 1.2.6 gem (from 1.1.12), I'm having
a new problem verifying routes that should not exist.

This is to support something like this in routes.rb:

map.resources :orders do |orders|
orders.resources :items, :except = [:index,:show]
end

I used to use lambda {}.should_raise( routing error ), but it stopped
detecting any raised error.  Requesting it through the browser produces
ActionController::MethodNotAllowed (Only post requests are allowed). But
that error wasn't detected.

When I skip the lambda, and just ask it to verify that the route does
exist (which *should* fail), I get the same result for those :except
actions as for a made-up action name.  Seems this must have something to
do with the change in how route_for delegates back to ActionController's
routing assertion (sez the backtrace :).


NoMethodError in 'ItemsController route generation should NOT map
#indewfefwex'
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.first
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:134:in
`recognized_request_for'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:49:in
`assert_recognizes'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions.rb:54:in
`clean_backtrace'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/assertions/routing_assertions.rb:47:in
`assert_recognizes'
./spec/controllers/thoughts_routing_spec.rb:9:


I tried using bypass_rescue in my routing/items_routing_spec.rb file as
mentioned by the upgrade doc, but it wasn't valid in the routing spec
- worked fine when I moved the file back to spec/controllers/, though. 
Seems like that's not the issue, but I'm mentioning for more completeness.


Any ideas what I should be doing instead, or how I can troubleshoot further?
  



Hmm.. yeah, it seems like it might have to do with how the exceptions 
are being handled in the newer version of rspec-rials (see 
https://rspec.lighthouseapp.com/projects/5645/tickets/85-11818-have-mode-for-rails-error-handling).  
I don't use RSpec to verify my routes very often and have never used it 
to verify the non-existence of a route so I'm afraid I don't really have 
any ideas...


Does anyone else have an idea to do this?

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [cucumber] -n command line option looks in every feature file

2009-05-08 Thread Ben Mabey

Mark Wilden wrote:
Running 'cucumber -n asdf features/challenge.feature' seems to load 
every feature file from the Rails root on down. In particular, it 
loads example features in vendor/gems like Ben's email_spec which 
requires Rails 2.2.2. This makes the command fail for us, since we've 
frozen 2.3.2. I would imagine it's also loading RSpec's own features, 
since that gem is also frozen in our app.


I don't know if this is defined behavior or not, but it was 
surprising. It makes the -n option less useful, IMO. What does the 
filespec do in this case?


///ark


What do you mean by filespec?  Regardless, I agree with you that this 
doesn't seem normal at all.  Care to add a ticket for it?


Thanks,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [cucumber] how to debug cucumber with netbeans?

2009-05-08 Thread Ben Mabey

Jean-Michel Garnier wrote:

3 months ago, I submitted a patch to cucumber so I could run cucumber from a
ruby script and use the debugger in netbeans
(https://rspec.lighthouseapp.com/projects/16211/tickets/128-running-feature-from-ruby-script)

It worked well at the time but I can't make it work with cucumber 0.3.2.
Here is the stacktrace:
ruby script/cucumber_netbeans_runner.rb 
cucumber features/_admin/projects.feature  --profile default 
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in

`gem_original_require': no such file to load -- lib/active_merchant
(MissingSourceFile)
Failed to load
./vendor/plugins/active_merchant/lib/support/gateway_support.rb from
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`polyglot_original_require'
from /Library/Ruby/Gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in
`require'
from
/Users/jeanmichel/Projects/betterplace/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in
`require'
from
/Users/jeanmichel/Projects/betterplace/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in
`new_constants_in'
from
/Users/jeanmichel/Projects/betterplace/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:496:in
`require'
from ./vendor/plugins/active_merchant/lib/support/gateway_support.rb:3
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`polyglot_original_require'
 ... 8 levels...
from
/Library/Ruby/Gems/1.8/gems/cucumber-0.3.2/lib/cucumber/cli/main.rb:20:in
`execute'
from script/cucumber_netbeans_runner.rb:29:in `run'
from script/cucumber_netbeans_runner.rb:21:in `run_feature'
from script/cucumber_netbeans_runner.rb:37

And the script:

require 'rubygems'
require 'cucumber/cli/main'

module Cucumber
  module Netbeans
class Runner
  def initialize(cucumber_opts=nil)
@argv = []
@cucumber_opts = cucumber_opts ||  --profile default
  end

  def run_scenario(line_number)
@cucumber_opts   --line #{line_number}
run
  end

  def run_feature(feature)
@argv  #{feature}
run
  end

  protected

  def run
@argv  @cucumber_opts

puts %Q{cucumber #...@argv.join(' ')} \n}
Cucumber::Cli::Main.execute(@argv)
  end
end
  end
end

Cucumber::Netbeans::Runner.new().run_feature
features/_admin/projects.feature

I wonder if fellow netbeans on cucumber users will have an idea ...
Ironically, debugging that script with netbeans crashes the debugger at
Library/Ruby/Gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54 


For the time being, I am using the old school ruby-debug which works
pretty well ...

JM
  



So, you can run the feature fine without the debugger?  What is 
confusing is that lib/active_merchant is showing up in the backtrace 
saying it can't be found... What if you try to run the feature with the 
debugger from outside of Netbeans?  Just trying to get an idea of who 
the culprit really is here.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] top posting and plain text

2009-05-06 Thread Ben Mabey




+ 1


aslak hellesoy wrote:
Folks,

*snip*

Thanks,
Aslak
  

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users




___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] top posting and plain text

2009-05-06 Thread Ben Mabey



Rick DeNatale wrote:

On Wed, May 6, 2009 at 7:33 PM, Ben Mabey b...@benmabey.com wrote:
  

+ 1


aslak hellesoy wrote:

Folks,

*snip*

Thanks,
Aslak



So let me get this right,

you agreed with Aslak that you shouldn't top post.

by top posting

  
lol.. Yes.   :)  Sarcasm somethings doesn't come across well over email 
I suppose.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] Using Cucumber to test Erlang servers directly

2009-05-02 Thread Ben Mabey

Jim Morris wrote:

I don't know if this will interest anyone, but I thought it was a
pretty cool use of Cucumber :)

I've posted a Blog article on how I use Cucumber to test an Erlang
Server directly by talking to my Erlang Nodes.

http://blog.wolfman.com/articles/2009/5/2/using-cucumber-to-test-erlang-servers

It uses Cucumber running under JRuby which uses JInterface to talk to
the Erlang servers.

I hope someone else finds this a fascinating use of Cucumber ;)



  


That is awesome.  Thanks for sharing!

-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] cucumber - how to bootstrap outside of rails?

2009-05-02 Thread Ben Mabey

Aslak Hellesøy wrote:




I use mkdir and touch.



Me too


Yeah, mkdir -p features/support  mkdir -p features/step_defnintions 
 touch features/support/env.rb is really all you need.


However, for new projects I really like to use jeweler to bootstrap all 
the setup for Cucumber, RSpec, Rakefiles, etc...  With jeweler you just 
say jeweler cool_gem --cucumber --rspec and all of this gets generated 
for you:

   create.gitignore
   createRakefile
   createLICENSE
   createREADME.rdoc
   create.document
   createlib
   createlib/cool_gem.rb
   createspec
   createspec/spec_helper.rb
   createspec/cool_gem_spec.rb
   createfeatures
   createfeatures/cool_gem.feature
   createfeatures/support
   createfeatures/support/env.rb
   createfeatures/step_definitions
   createfeatures/step_definitions/cool_gem_steps.rb

Here is jewelers site:  http://technicalpickles.github.com/jeweler/


-Ben







On May 1, 11:25 pm, James Byrne li...@ruby-forum.com wrote:

Setting up cucumber inside a Rails project is no more difficult than
running script/generate cucumber.  But what does one do when working
without Rails at all?  How do you generate the features tree and all of
its default files?
--
Posted viahttp://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users 


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] cucumber - referential (inherited?) scenarios

2009-05-02 Thread Ben Mabey

Julian Leviston wrote:

You know what'd be awesome?

If Cucumber scenarios were referential.

I mean, wouldn't it be awesome if you could refer to them... so you 
could build on them...


So in a login.feature I'd define:

Scenario: logging in
Given that a default user exists
And I am on the login page
When I fill in username with username
And I fill in password with password
Then I should be logged in

And then in a different feature somewhere else, I could say:

another.feature

Scenario: make toast
Given Scenario logging in
Given I am on the exciting logged in page
Then I  blah blah blah

and so on...

Julian.



Believe it or not, this exact feature did exist in Cucumber at one time 
but was deprecated and is now removed.  You can find a good explanation 
of the reasoning behind that decision and what are the better 
alternatives on Joseph's blog:


http://blog.josephwilk.net/ruby/cucumber-waves-goodbye-to-givenscenario.html

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] cucumber - referential (inherited?) scenarios

2009-05-02 Thread Ben Mabey

Julian Leviston wrote:

Fair enough.

The steps from step definitions one is the best approach for what I 
want, and it's actually what am doing, but I do notice that there's a 
lot of the time when I'm actually re-typing the same text (ie once in 
the explicit explanation of what it means to log in, and then once 
more in the step definitions to refer to that login procedure) when I 
do this approach. Re-typing the same stuff is pretty retarded, and 
never a good idea.


Hence... my interest in this feature :)

How about this... Whenever I refer to other steps from within my 
steps, they should be printed out on the output line... tabbed in a 
bit, like so:


Given I am logged in:
Given a default user exists
And I am on the login page
And I fill in username with username
And I fill in password with password
Then I should be on the superduper page
Given...
When...
Then...

Then the option to turn this feature off or on on the command line.


We would definitely want it as a feature you could turn on or off.  By 
default I think it should be off.  I think it adds a lot of noise to the 
feature output.  In most cases I don't care what the exact steps of 
logging in are.  How I log in can change and it doesn't really effect 
this scenario at all.  What is important is that you are logged in- not 
how you got there.  So this is probably not a feature I would personally 
use.  (Especially, given that I don't use steps within steps a whole 
lot.)  That said it seems like a reasonable request... Any other 
opinions on the suggested feature?  Should we move the discussion to 
lighthouse?


-Ben



That'd be bloody brilliant. Okay so maybe I should go fork it and do 
it :)


Julian.

On 03/05/2009, at 4:50 AM, Ben Mabey wrote:


Julian Leviston wrote:

You know what'd be awesome?

If Cucumber scenarios were referential.

I mean, wouldn't it be awesome if you could refer to them... so you 
could build on them...


So in a login.feature I'd define:

Scenario: logging in
Given that a default user exists
And I am on the login page
When I fill in username with username
And I fill in password with password
Then I should be logged in

And then in a different feature somewhere else, I could say:

another.feature

Scenario: make toast
Given Scenario logging in
Given I am on the exciting logged in page
Then I  blah blah blah

and so on...

Julian.



Believe it or not, this exact feature did exist in Cucumber at one 
time but was deprecated and is now removed.  You can find a good 
explanation of the reasoning behind that decision and what are the 
better alternatives on Joseph's blog:


http://blog.josephwilk.net/ruby/cucumber-waves-goodbye-to-givenscenario.html 



-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Before and After blocks for individual feature files?

2009-05-01 Thread Ben Mabey

Korny Sietsma wrote:

Celerity is very cool - when it works.  It didn't work with out messy
combination of javascript libraries, alas.  (Dojo 0.4-ish for legacy
bits, GWT for new bits) - apparently it will work with either of these
frameworks, but for us, with both, it died mysteriously (and we gave
up trying to fix it due to limited time)

- Korny
  


Yeah, I have had similar experiences with Celerity.  To be fair, it is 
not Celerity's shortcoming but rather it is HTMLUnit's and Rhino's for 
not being able to support all the JS frameworks yet.  If you don't have 
a legacy system though I think Celerity is the way to go for JS testing.


-Ben


On Fri, May 1, 2009 at 10:08 PM, Ben Lovell benjamin.lov...@gmail.com wrote:
  

On Fri, May 1, 2009 at 12:33 PM, Matt Wynne m...@mattwynne.net wrote:


Have you looked at celerity? I'm not sure if webrat has an adapter for it
yet, but it's a 'headless' browser which drives a lot faster than selenium.
Some people on this list are getting a lot of joy out of it.
  

+1 to celerity. You need to jump through some hoops with JRuby/Java but it
cut the time it takes to run my features by 3-4 times almost.

Ben

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users






  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Plugin to generate text logs using cucumber.

2009-05-01 Thread Ben Mabey

Ben Lovell wrote:
On Fri, May 1, 2009 at 7:22 PM, Anil Gollaa li...@ruby-forum.com 
mailto:li...@ruby-forum.com wrote:


Hi,
I was able to run the scenarios using rake features in cucmber,
All the respective results are displayed in colour in std output.

is there any plugin using which i can capture these results(that are
generated at run time).
Please let me know the procedure to capture these logs in to a files.


cucumber features -o FILE

Where FILE is the name of the file to redirect the output to.

Ben 
  
You will probably not want the color so you can use the --no-color 
flag.  FYI, you can specify multiple formatters if you need to.  
cucumber --help for more.


Ben Mabey
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Command to run a single scenario using cucumber

2009-05-01 Thread Ben Mabey

Anil Gollaa wrote:

Hi,
I have installed cucumber and was able to run all the scenarios using
rake features, but can body tell me.
What is the command to run a single scenario?

Thanks,
Anil kumar.
  


bma...@benzii:~/$ cucumber --help
Usage: cucumber [options] [ [FILE|DIR|URL][:LINE[:LINE]*] ]+

Examples:
cucumber examples/i18n/en/features
cucumber --language it examples/i18n/it/features/somma.feature:6:98:113
cucumber -n -i http://rubyurl.com/eeCl
...
...



So, to run a single scenario you just need to specify it's line number 
with the colon syntax. cucumber features/something.feature:42


Using the cucumber binary is the preferred way of running cucumber.  I 
like to reserve using the rake task for CI servers.


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [cucumber] Bug introduced in 0.3.1

2009-04-30 Thread Ben Mabey

Lee Hambley wrote:

Hi All,

I'm new to the list, but a happy cucumber user with a few weeks 
experience now... a bit of a shock this morning when someone upgraded 
here and happened to jump up to 0.3.1, we're seeing the following 
output.. 

I haven't had chance to investigate more, but I will try to.. this 
goes away if we roll back to 0.3.0.


* http://gist.github.com/104429

I also listed the relevant local gems as far as I can see, I'll post 
back here if I come up with anything, pointers or suggestions would be 
welcomed!


Thank you,

 Lee Hambley



What is your rails environment file? (test.rb)

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber - Testing ActionMailer

2009-04-29 Thread Ben Mabey

James Byrne wrote:

James Byrne wrote:
  

I have reached this point in testing using email-spec:


...
  
The email To: header value and the current_email_address are the same 
insofar as I can tell.  But the email_spec matcher is not finding that 
address in the deliveries array.  Any ideas as to what I am missing?



I have determined what the problem is. I just do not know how to fix it.

What is happening is that I am testing a standalone (outside of a Rails 
instance) Ruby script that requires ActionMailer.  I call this script 
from inside the step definition using the %x alias for Kernel#`. When 
this runs it picks up the test environment and directs email output into 
ActionMailer::Base.deliveries.  However, this array only exists during 
the script's existence and naturally disappears when he script 
terminates. In consequence, the results are not available for testing.


I have, up to now, simply accepted the magic of injecting test methods 
into classes and using the results.  Now I need to have explained how I 
get this to magic work with stand alone scripts.  How do I get 
ActionMailer::Base.deliveries created by ActionMailer in the script to 
remain available to cucumber/email-spec?
  


I have plans to make email-spec work with any SMTP mailer and thereby 
making it more black-boxy and allow for external processes to be 
easily tested... However, that is not done yet.  As it stands now you 
have two options: a) have the test execution and script in the same 
process or b) Use ARMailer[1] in your testing environment.  ARMailer 
places the messages in a database for queuing.  So instead of checking 
the in-memory array EmailSpec will check the queue on the database.  
Since this is just for testing then you could use a lightweight sqlite3 
db to store this. 


-Ben

1. http://github.com/seattlerb/ar_mailer/tree/master
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob question

2009-04-29 Thread Ben Mabey

Korny Sietsma wrote:

True, but cucumber is useful for lots of different kinds of projects.
I'm currently using it to build a java webapp, so I don't need much
beyond cucumber, selenium, and selenium-client.
  
I'm curious, with your current setup do you insert data directly into 
your database (i.e. in Given steps) or do you always use the selenium to 
enter in data.  Meaning, if you needed a user to exist so you could have 
them log in.. do you use ActiveRecord, or something similar, to create 
the user or do you use the webforms to create the user?  Also, how do 
you handle cleaning the database after each scenario?  Sorry, for the 
questions, but I'm curious how you've solved these problems when using 
Cucumber to test a non-ruby webapp.


Thanks,
Ben



But agreed, if I was in rails-land (sigh) then I'd want webrat and rspec-rails.

- Korny
p.s. I'm aware webrat works without rails, but when I looked it didn't
seem a big boost for our kind of app.

On Wed, Apr 29, 2009 at 10:42 PM, Chris Flipse cfli...@gmail.com wrote:
  

On Wed, Apr 29, 2009 at 7:42 AM, Korny Sietsma ko...@sietsma.com wrote:


Presumably you only need these if you are *building* cucumber?

If you just want to use cucumber, it should be as simple as gem
install cucumber, and it should get all the other dependencies.  On
my machine it seemed to install treetop, polyglot, and presumably a
few others - but I don't have rspec-rails nor webrat.
  

rspec(-rails) and webrat aren't actually *required* by Cucumber -- you can
use it without them, which is why they're not force-installed.  However,
nearly every example you're going to find of Cucumber run against a rails
app is going to be using webrat and rspec-rails ...



--
// anything worth taking seriously is worth making fun of
// http://blog.devcaffeine.com/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users






  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob question

2009-04-29 Thread Ben Mabey

Korny Sietsma wrote:

We are actively debating this very topic :)

For most stuff, we create data through the UI.

We have a Before block that prunes the database back to a known
state before each scenario, using the ruby 'sequel' library.  It's
pretty fast, but it does mean we have to be careful in our selenium,
that we wait for the database as seen by the app to catch up with the
database session committed by the ruby code.

And then our scenarios have stuff like Given a top-level node called
Foo exists - which creates the node via selenium.

However there are some areas where this is just too slow, and we have
created some 'Given' steps that use ruby-sequel code that build up
data directly in the database.  This does mean duplicating some of our
Java domain in the ruby code, but it seemed to be a pragmatic solution
to the problem.
  


Have you considered running Cucumber with JRuby so you can leverage your 
Java code to insert records into the DB?  Just an idea.

Currently we are debating whether to make more 'Given' steps directly
push data into the database - there are pros and cons either way;
using the UI gives us more confidence in our app (and less fragility
if our domain changes) and requires less code (we can reuse 'when'
steps from some scenarios as 'given' steps for others) but it's slower
- and the accumulated effect of slow builds can be terrible.
  


As far as the confidence aspect goes, it seems that you should gain 
enough confidence by having Cucumber fill out each form once then insert 
the data directly the other times.  That is at least how I approach 
things in webrat world.  But you are right about all of the trade-offs 
and that is why I am curious on how you are solving them.  Thanks for 
sharing!


-Ben


On Thu, Apr 30, 2009 at 9:32 AM, Ben Mabey b...@benmabey.com wrote:
  

Korny Sietsma wrote:


True, but cucumber is useful for lots of different kinds of projects.
I'm currently using it to build a java webapp, so I don't need much
beyond cucumber, selenium, and selenium-client.

  

I'm curious, with your current setup do you insert data directly into your
database (i.e. in Given steps) or do you always use the selenium to enter in
data.  Meaning, if you needed a user to exist so you could have them log
in.. do you use ActiveRecord, or something similar, to create the user or do
you use the webforms to create the user?  Also, how do you handle cleaning
the database after each scenario?  Sorry, for the questions, but I'm curious
how you've solved these problems when using Cucumber to test a non-ruby
webapp.

Thanks,
Ben




But agreed, if I was in rails-land (sigh) then I'd want webrat and
rspec-rails.

- Korny
p.s. I'm aware webrat works without rails, but when I looked it didn't
seem a big boost for our kind of app.

On Wed, Apr 29, 2009 at 10:42 PM, Chris Flipse cfli...@gmail.com wrote:

  

On Wed, Apr 29, 2009 at 7:42 AM, Korny Sietsma ko...@sietsma.com wrote:



Presumably you only need these if you are *building* cucumber?

If you just want to use cucumber, it should be as simple as gem
install cucumber, and it should get all the other dependencies.  On
my machine it seemed to install treetop, polyglot, and presumably a
few others - but I don't have rspec-rails nor webrat.

  

rspec(-rails) and webrat aren't actually *required* by Cucumber -- you
can
use it without them, which is why they're not force-installed.  However,
nearly every example you're going to find of Cucumber run against a rails
app is going to be using webrat and rspec-rails ...



--
// anything worth taking seriously is worth making fun of
// http://blog.devcaffeine.com/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users






  

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users






  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Before and After blocks for individual feature files?

2009-04-28 Thread Ben Mabey

Arco wrote:

I'd like to do this:

  Feature: user signup
  Before:
Given I have a cleaned up database
  Scenario Outline: Sign Up
Given I am on the signup page
When I sign up using userid
Then I should see message
   Examples:
|userid |message   |
|userX  |successful signup |
|userX  |duplicate userid  |

I have a cleaned up database runs before every example, making the
second example ('duplicate userid') fail.
  



You could use Background and it would work just like you want it to:

 Feature: user signup
 Background:
   Given I have a cleaned up database
 Scenario Outline: Sign Up
   Given I am on the signup page
   When I sign up using userid
   Then I should see message
  Examples:
   |userid |message   |
   |userX  |successful signup |
   |userX  |duplicate userid  |


However, I would not encourage this.  You should try to avoid using technical words, such as 
database, in your features.  If anything you could say Given no users exist or 
something like that.  Keeping your database clean is something you generally want for every 
scenario though.  So I would suggest putting the code in your Given I have a cleaned up 
database code into a Before block.  The wiki has a page on using the Before hook: 
http://wiki.github.com/aslakhellesoy/cucumber/hooks

Basically, in your env.rb file you will add something like:

Before do
 Database.clean! # or however you clean your DB
end



HTH,
Ben



On Apr 28, 9:38 am, aslak hellesoy aslak.helle...@gmail.com wrote:
  

On Tue, Apr 28, 2009 at 6:15 PM, Arco akl...@gmail.com wrote:


OK - I found a workaround.  I simply tag the first scenario with
'@first', then
do Before('@first') and i get what I want - executing a block once for
the feature file.
  
Except for one problem:  most of my scenarios are done as scenario

outlines, which
are run multiple times - once for each row of my Example table.
  
A workaround to that problem might be to put a 'dummy' scenario that

is run before the other scenarios in my feature file...
  
 @first

 Scenario: Call a before block before running other scenarios...
  
But this puts junk in my feature files.  Is there a better, cleaner

way??
  

a) Why do you need one thing to happen before a feature?
b) Why can't you do it before each scenario?

Aslak





On Apr 28, 8:32 am, Arco akl...@gmail.com wrote:
  

I also would like a hook that executes a block once before running a
feature file.

In my testing i found that:

- Background: executes before each scenario
- Before executes before each scenario
- Before('@tag') executes before each scenario

Is there a way to execute a block once before each feature, but not

before each scenario?

On Apr 28, 7:08 am, aslak hellesoy aslak.helle...@gmail.com wrote:


Hi -- is it possible to set before and after blocks for individual


feature
  

files?


Yes. Use tagged hooks:
  

http://wiki.github.com/aslakhellesoy/cucumber/hooks
  

Aslak
  

I've tried putting them in step files, but they just get called


before
  

everything, like they'd been declared in env.rb, which is consistent


with
  

how I thought cucumber worked, but I thought I'd best try it anyway.
Anyway, I have some features that require a specific state be set up


before
  

they run -- is this possible to do, and how would I go about doing


it?
  

Thanks for any  all help,
   Doug.

___

rspec-users mailing list
rspec-us...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://
  

rubyforge.org/mailman/listinfo/rspec-users
  

___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://


rubyforge.org/mailman/listinfo/rspec-users
___
rspec-users mailing list
rspec-us...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Before and After blocks for individual feature files?

2009-04-28 Thread Ben Mabey

Arco wrote:

Thanks for your reply Ben.  +1 on your wording recommendation - I
understand and agree 100%

However - for me - the Background block executes before each example
in the table.  Therefore, the database is cleared twice, and the
second example ('duplicate userid') fails.

(Cucumber 0.3.1 / ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin])

Here are some snippets from a little workaround that i've employed...
in env.rb:
  State = {'feature_file'='initialize'}
in my_steps.rb:
  unless State['feature_file'] ==
@__cucumber_current_step.file_colon_line.split(':').first
puts CLEANUP CODE HERE - RUN ONCE PER FEATURE FILE  
  end
  State['feature_file'] =
@__cucumber_current_step.file_colon_line.split(':').first

I'm sure there must be a better way!  I am still learning cucumber so
any advice is welcome!
;-)
  


While the above code is clever I would discourage its use.  IMO, it 
looks like you are trying too hard to phrase your scenarios all within a 
single scenario outline.  In this case I would not use tables but I 
would have separate scenarios.  For example:


 Feature: user signup

 Scenario: success
   Given I am on the signup page

   When I enter valid registration information
   And I press Register

   Then I should see You have signed up successfully!

 Scenario: duplicate user with email # dunno, what really qualifies as 
duplicate for you...
   Given I am on the signup page
   And a user with email f...@bar.com exists
   
   When I enter valid registration information
   And I fill in Email with f...@bar.com

   And I press Register

   Then I should see A user has already signed up with f...@bar.com



Does that make sense?  Basically, whenever you feel the need to embed a 
conditional in your scenario it means you need a separate one.  You can 
sometimes accomplish this by using scenario tables but that constrains you to 
the same setup steps.  In your case you wanted additional context for one of 
your scenarios in the table... this means that you probably should have a whole 
new scenario like above.  Your current solution obfuscates the additional 
context and therefore looses some of the documentation value that Cucumber 
offers.

FWIW.

Oh, and please try not to top-post in the future - it makes threads hard to 
follow. :)


-Ben





On Apr 28, 11:28 am, Ben Mabey b...@benmabey.com wrote:
  

Arco wrote:


I'd like to do this:
  
  Feature: user signup

  Before:
Given I have a cleaned up database
  Scenario Outline: Sign Up
Given I am on the signup page
When I sign up using userid
Then I should see message
   Examples:
|userid |message   |
|userX  |successful signup |
|userX  |duplicate userid  |
  
I have a cleaned up database runs before every example, making the

second example ('duplicate userid') fail.
  

You could use Background and it would work just like you want it to:

  Feature: user signup
  Background:
Given I have a cleaned up database
  Scenario Outline: Sign Up
Given I am on the signup page
When I sign up using userid
Then I should see message
   Examples:
|userid |message   |
|userX  |successful signup |
|userX  |duplicate userid  |

However, I would not encourage this.  You should try to avoid using technical words, such as 
database, in your features.  If anything you could say Given no users exist or 
something like that.  Keeping your database clean is something you generally want for every 
scenario though.  So I would suggest putting the code in your Given I have a cleaned up 
database code into a Before block.  The wiki has a page on using the Before 
hook:http://wiki.github.com/aslakhellesoy/cucumber/hooks

Basically, in your env.rb file you will add something like:

Before do
  Database.clean! # or however you clean your DB
end

HTH,
Ben





On Apr 28, 9:38 am, aslak hellesoy aslak.helle...@gmail.com wrote:
  

On Tue, Apr 28, 2009 at 6:15 PM, Arco akl...@gmail.com wrote:


OK - I found a workaround.  I simply tag the first scenario with
'@first', then
do Before('@first') and i get what I want - executing a block once for
the feature file.
  
Except for one problem:  most of my scenarios are done as scenario

outlines, which
are run multiple times - once for each row of my Example table.
  
A workaround to that problem might be to put a 'dummy' scenario that

is run before the other scenarios in my feature file...
  
 @first

 Scenario: Call a before block before running other scenarios...
  
But this puts junk in my feature files.  Is there a better, cleaner

way??
  

a) Why do you need one thing to happen before a feature?
b) Why can't you do it before each scenario?

Aslak


On Apr 28, 8:32 am, Arco akl...@gmail.com wrote:
  

I also would like a hook that executes a block once before running a
feature file.

In my testing i

Re: [rspec-users] Before and After blocks for individual feature files?

2009-04-28 Thread Ben Mabey

Julian Leviston wrote:

Hey Ben,

It'd be kinda cool if there was a sort of before and after for a 
feature rather than each scenario. Is there?


Nope.  There is no before(:all) equivalent in cucumber.  Just the Before 
and After hooks, which are for scenarios.. and Backgrounds which are 
just for scenarios on the given feature.


(Rails context) We often need this. It'd be really helpful for things 
like when we want to test about 15 things on a particular web page, 
and they don't require fresh data. We end up with a login and setup 
type background which gets run every time rather than simply once.
In the context of webrat a before(:all) would not help you a whole lot 
since each scenario starts with a new session (so you have to login each 
time, for example).  I understand the argument for complex data setup 
though.  Having the same setup ran for each scenario can get costly.  I 
haven't felt enough pain though to really justify adding something like 
that.  Cleanup would be messy because we couldn't wrap it all in a 
transaction AFAIK, so you would have to have an after(:all) like method 
to clean up the feature.  For complex data that I rely on all the time I 
tend to load it once with fixtures at boot up time within env.rb.  This 
is usually for look-up data... but if you were really concerned about 
record creation you could do something similar.  The question is if the 
additional complexity of keeping all that global state in your head 
worth the faster execution time.  For me it generally is not.


I guess we could refactor it into a set of examples perhaps... would 
that work? It just strikes me as quite complicated. It'd be awesome if 
we had sub-scenarios (and they could be specified to levels) ;-) 
Perhaps I'm just being too complicated.


I would need more context to really answer your question.  However, can 
I ask if your scenarios are written in a declarative or imperative 
fashion[1]?  If they are written declaratively, or at least partly, then 
you can specify a lot more behavior in a step without adding too much 
noise to the scenario.  Another thing I should point out is that you 
don't need to, and you shouldn't, test everything on the Cucumber 
level.  For complex views, for example, it may be easier to do RSpec 
examples (view specs) and just use Cucumber to test the basics.  In 
general, I'm pretty wary about sub-scenarios and the like.  They could 
be powerful, but they could very easily get complicated and turn 
scenarios into a giant mess that only programmers could understand.  
Feel free to share any ideas you have on the subject though and we'll 
see what the tradeoffs are.  We love throwing new ideas around on the 
list. :)


I loved your rubyconf talk presentation, BTW. We kinda took exception 
to the bit where you said Selenium just works, though. There are a 
number of things where the connection between selenium and webrat is a 
little tenuous and finicky about.


Thanks!  Yeah, the selenium adapter in webrat isn't nearly as mature as 
the rails adapter. :(  I haven't had a lot of issues with it, but I try 
to use it as least as possible and have only really used it on simple 
things.  And to be honest, I haven't used it since January.  So, YMMV.


Also we seem to be having timing issues for AJAX requests with 
Selenium. Webrat doesn't seem to want to wait until the AJAX request 
as finished before doing the next thing. Any ideas here? 
I think I have seen people in #webrat on irc.freenode.net talk about 
that and how they've had to add additional wait commands in. But, I 
really don't know any details.  Sorry!  Your best bet is to ask in 
#webrat, or on it's google group or lighthouse account.


-Ben

1. 
http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/


On 29/04/2009, at 4:28 AM, Ben Mabey wrote:


Arco wrote:

I'd like to do this:

Feature: user signup
Before:
  Given I have a cleaned up database
Scenario Outline: Sign Up
  Given I am on the signup page
  When I sign up using userid
  Then I should see message
 Examples:
  |userid |message   |
  |userX  |successful signup |
  |userX  |duplicate userid  |

I have a cleaned up database runs before every example, making the
second example ('duplicate userid') fail.




You could use Background and it would work just like you want it to:

Feature: user signup
Background:
 Given I have a cleaned up database
Scenario Outline: Sign Up
 Given I am on the signup page
 When I sign up using userid
 Then I should see message
Examples:
 |userid |message   |
 |userX  |successful signup |
 |userX  |duplicate userid  |


However, I would not encourage this.  You should try to avoid using 
technical words, such as database, in your features.  If anything you 
could say Given no users exist or something like that.  Keeping 
your database clean is something you generally want for every 
scenario though.  So I would suggest putting the code in your

Re: [rspec-users] Problems running features with Textmate Cucumber bundle

2009-04-27 Thread Ben Mabey

Rick DeNatale wrote:

On Mon, Apr 27, 2009 at 10:07 AM, aslak hellesoy
aslak.helle...@gmail.com wrote:
  

On Mon, Apr 27, 2009 at 3:47 PM, Rick DeNatale rick.denat...@gmail.com
wrote:


On Mon, Apr 27, 2009 at 8:13 AM, Rick DeNatale rick.denat...@gmail.com
wrote:
  

On Sun, Apr 26, 2009 at 11:38 PM, Ben Mabey b...@benmabey.com wrote:


Rick DeNatale wrote:
  

I finally plunked down for the beta RSpec bundle and I'm working
through the initial example.  Although I'm a fairly experienced RSpec
user, I'm stlll learning new tricks.

Anyway,  I'm going though the mastermind example, and everything is
going well, except that I decided to also try out the Textmate bundle
for Cucumber.  I decided to use Ben Mabey's fork on github since it
seems to be the most evolved.

When I try to run a feature with cmd-R, instead of actually running I
see something like:

Running: cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html
false

Cucumber runs fine from bash.

Am I missing some setup?




Hmm.. that is odd. What version of Cucumber are you using?  When you
run
that exact command from the shell does it output the HTML report?
  

I was runing 0.3.0 upgrading to 0.3.1 has the same result BUT

If I run that exact command

$ /Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html
-bash: /Users/rick/mastermind/features/codebreaker_starts_game.feature:
Permission denied


It's trying to run the feature as an executable directly it's not
running the cucumber executable!

Why it be doin dat?


Actually, I was misreading the output in the run window, which was
wrapping.

$  cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html false

/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/step_mother.rb:125:in
`Given': Multiple step definitions have the same Regexp:
(Cucumber::Redundant)

features/step_definitions/mastermind.rb:13:in `/^I am not yet playing$/'
features/step_definitions/mastermind.rb:13:in `/^I am not yet playing$/'

   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/step_mother.rb:124:in
`each'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/step_mother.rb:124:in
`Given'
   from ./features/step_definitions/mastermind.rb:13
   from
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
   from
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`polyglot_original_require'
   from
/opt/local/lib/ruby/gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in
`require'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:79:in
`require_files'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:77:in
`each'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:77:in
`require_files'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:34:in
`execute!'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:20:in
`execute'
   from /Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/cucumber:6
   from /opt/local/bin/cucumber:19:in `load'
   from /opt/local/bin/cucumber:19

If I do this from the project directory:

 $ cucumber features/codebreaker_starts_game.feature
Feature: Codebreaker starts game
 As a Codebreaker
 I want to start a game
 So that I can break the code

 Scenario: Start game#
features/codebreaker_starts_game.feature:5
   Given I am not yet playing#
features/step_definitions/mastermind.rb:13
   When I start a new game   #
features/step_definitions/mastermind.rb:24
   Then the game should say Welcome to Mastermind! #
features/step_definitions/mastermind.rb:28
   And the game should say Enter guess:#
features/step_definitions/mastermind.rb:28

1 scenario
4 passed steps


Running under textmate, cucumber seems to be somehow convincing itself
that
features/step_definitions/mastermind.rb:13:in `/^I am not yet playing$/'

Duplicates itself?!?
  

What's happening is that the file containing step defs is being loaded
twice, and therefore you get dupe step defs. Not sure why that's happening
though...



Yes, I figured it was somehing like that. On a little more trial and
error, it appears that the bundle is adding false to the end of the
command string which is causing that steps def to be required
initially:

$ cucumber /Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html false -v
Ruby files required:
  * /Users/rick/mastermind/features/support/env.rb
  * ./features/support/env.rb
  * ./lib/mastermind/game.rb
  * /Users/rick/mastermind/features/step_definitions/mastermind.rb
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib

Re: [rspec-users] Problems running features with Textmate Cucumber bundle

2009-04-27 Thread Ben Mabey

Rick DeNatale wrote:

On Mon, Apr 27, 2009 at 10:07 AM, aslak hellesoy
aslak.helle...@gmail.com wrote:
  

On Mon, Apr 27, 2009 at 3:47 PM, Rick DeNatale rick.denat...@gmail.com
wrote:


On Mon, Apr 27, 2009 at 8:13 AM, Rick DeNatale rick.denat...@gmail.com
wrote:
  

On Sun, Apr 26, 2009 at 11:38 PM, Ben Mabey b...@benmabey.com wrote:


Rick DeNatale wrote:
  

I finally plunked down for the beta RSpec bundle and I'm working
through the initial example.  Although I'm a fairly experienced RSpec
user, I'm stlll learning new tricks.

Anyway,  I'm going though the mastermind example, and everything is
going well, except that I decided to also try out the Textmate bundle
for Cucumber.  I decided to use Ben Mabey's fork on github since it
seems to be the most evolved.

When I try to run a feature with cmd-R, instead of actually running I
see something like:

Running: cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html
false

Cucumber runs fine from bash.

Am I missing some setup?




Hmm.. that is odd. What version of Cucumber are you using?  When you
run
that exact command from the shell does it output the HTML report?
  

I was runing 0.3.0 upgrading to 0.3.1 has the same result BUT

If I run that exact command

$ /Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html
-bash: /Users/rick/mastermind/features/codebreaker_starts_game.feature:
Permission denied


It's trying to run the feature as an executable directly it's not
running the cucumber executable!

Why it be doin dat?


Actually, I was misreading the output in the run window, which was
wrapping.

$  cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html false

/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/step_mother.rb:125:in
`Given': Multiple step definitions have the same Regexp:
(Cucumber::Redundant)

features/step_definitions/mastermind.rb:13:in `/^I am not yet playing$/'
features/step_definitions/mastermind.rb:13:in `/^I am not yet playing$/'

   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/step_mother.rb:124:in
`each'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/step_mother.rb:124:in
`Given'
   from ./features/step_definitions/mastermind.rb:13
   from
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
   from
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`polyglot_original_require'
   from
/opt/local/lib/ruby/gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in
`require'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:79:in
`require_files'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:77:in
`each'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:77:in
`require_files'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:34:in
`execute!'
   from
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib/cucumber/cli/main.rb:20:in
`execute'
   from /Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/cucumber:6
   from /opt/local/bin/cucumber:19:in `load'
   from /opt/local/bin/cucumber:19

If I do this from the project directory:

 $ cucumber features/codebreaker_starts_game.feature
Feature: Codebreaker starts game
 As a Codebreaker
 I want to start a game
 So that I can break the code

 Scenario: Start game#
features/codebreaker_starts_game.feature:5
   Given I am not yet playing#
features/step_definitions/mastermind.rb:13
   When I start a new game   #
features/step_definitions/mastermind.rb:24
   Then the game should say Welcome to Mastermind! #
features/step_definitions/mastermind.rb:28
   And the game should say Enter guess:#
features/step_definitions/mastermind.rb:28

1 scenario
4 passed steps


Running under textmate, cucumber seems to be somehow convincing itself
that
features/step_definitions/mastermind.rb:13:in `/^I am not yet playing$/'

Duplicates itself?!?
  

What's happening is that the file containing step defs is being loaded
twice, and therefore you get dupe step defs. Not sure why that's happening
though...



Yes, I figured it was somehing like that. On a little more trial and
error, it appears that the bundle is adding false to the end of the
command string which is causing that steps def to be required
initially:

$ cucumber /Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html false -v
Ruby files required:
  * /Users/rick/mastermind/features/support/env.rb
  * ./features/support/env.rb
  * ./lib/mastermind/game.rb
  * /Users/rick/mastermind/features/step_definitions/mastermind.rb
/Users/rick/.gem/ruby/1.8/gems/cucumber-0.3.1/bin/../lib

Re: [rspec-users] Problems running features with Textmate Cucumber bundle

2009-04-27 Thread Ben Mabey

Rick DeNatale wrote:

On Mon, Apr 27, 2009 at 11:42 AM, Ben Mabey b...@benmabey.com wrote:
  

Do you happen to be explicitly requiring any of your step definitions from
your env.rb or other files?  What does your env.rb look like?




Yes, env.rb is right out of the RSpec book B4.0 'printing' p 43

$:  File.join(File.dirname(__FILE__), /../../lib )
require 'spec/expectations'
require 'mastermind'

You are right that the false is being output by running the command,
not the command line.  I hacked the runner.rb file in the bundle to
insert a br\ between outputting and running the command.

The mystery is why the same command running in Textmate reloads the
spec definition, but not when invoked by bash?  And when I add false
to the end of the command in bash it does.

Having just typed that I realize that I wasn't really sure that the
reload WAS the problem running under textmate. So I hacked the run
method in runner.rb in the bundle to show stderr as well as stdout:

in_project_dir do
  @output  %Q{Running: #{full_command = bash \21
#{command} #...@file.rake_task} #{argv.join(' ')}\} \n}
  @output  br\
  @output  Kernel.system(full_command)
end

And this outputs:

Running: bash 21 cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html
bash: 21 cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html: No such file or directory false

I'm guessing that the file it isn't finding is cucumber?  Is there an
environment variable I need to set in textmate?



  


Ahh, I've had similar issues with RSpec's bundle before.  Basically, 
your PATH is not being used for all of your OSX applications. From the 
rspec site[1]:


You may need to adjust the PATH in your ~/.MacOSX/environment.plist file 
to point to the directory

where your ruby and spec executables live. For example:

keyPATH/key
string/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/usr/local/mysql/bin/string



I will also add a TM_CUCUMBER_BIN constant option so if that is set it 
will use that instead of assuming 'cucumber' is in your path.  I'll let 
you know when that is done.


-Ben



1.http://rspec.info/documentation/tools/extensions/editors/textmate.html
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Problems running features with Textmate Cucumber bundle

2009-04-27 Thread Ben Mabey

Ben Mabey wrote:

Rick DeNatale wrote:

On Mon, Apr 27, 2009 at 11:42 AM, Ben Mabey b...@benmabey.com wrote:
 
Do you happen to be explicitly requiring any of your step 
definitions from

your env.rb or other files?  What does your env.rb look like?




Yes, env.rb is right out of the RSpec book B4.0 'printing' p 43

$:  File.join(File.dirname(__FILE__), /../../lib )
require 'spec/expectations'
require 'mastermind'

You are right that the false is being output by running the command,
not the command line.  I hacked the runner.rb file in the bundle to
insert a br\ between outputting and running the command.

The mystery is why the same command running in Textmate reloads the
spec definition, but not when invoked by bash?  And when I add false
to the end of the command in bash it does.

Having just typed that I realize that I wasn't really sure that the
reload WAS the problem running under textmate. So I hacked the run
method in runner.rb in the bundle to show stderr as well as stdout:

in_project_dir do
  @output  %Q{Running: #{full_command = bash \21
#{command} #...@file.rake_task} #{argv.join(' ')}\} \n}
  @output  br\
  @output  Kernel.system(full_command)
end

And this outputs:

Running: bash 21 cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html
bash: 21 cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature
--format=html: No such file or directory false

I'm guessing that the file it isn't finding is cucumber?  Is there an
environment variable I need to set in textmate?



  


Ahh, I've had similar issues with RSpec's bundle before.  Basically, 
your PATH is not being used for all of your OSX applications. From the 
rspec site[1]:


You may need to adjust the PATH in your ~/.MacOSX/environment.plist 
file to point to the directory

where your ruby and spec executables live. For example:

keyPATH/key
string/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/usr/local/mysql/bin/string 





I will also add a TM_CUCUMBER_BIN constant option so if that is set it 
will use that instead of assuming 'cucumber' is in your path.  I'll 
let you know when that is done.

http://github.com/bmabey/cucumber-tmbundle/commit/8516e1c40cf6181e35d45db943de374d7516fcc1

Try updating the bundle and defining a TM_CUCUMBER_BIN in Textmate 
(Textmate - Preferences - Advanced - Shell Variables).


Let me know how it goes.

Thanks,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [cucumber] Where does STDOUT go?

2009-04-27 Thread Ben Mabey

James Byrne wrote:

If one invokes a Ruby script from a cucumber step definition and that
script contains puts statements then where does the output go?  I have
a script that when run from the command line displays puts output in
the terminal session, but when run from a cucumber step definition
produces no console output.  It does however produce the expected output
file in either case.
  


If you are running the command with the backticks it is simply being 
returned to that call.  If you want to see that ouput you could add a 
puts.. for example:


puts `some_command`


If you are testing a CLI tool you may want to look how Cucumber's and 
RSpec's features capture and use the STDOUT and STDERR.


http://github.com/aslakhellesoy/cucumber/blob/0e9f6066bbed0e0b73f4af0a18f186a7e13fea46/features/support/env.rb

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber - Testing ActionMailer

2009-04-27 Thread Ben Mabey

James Byrne wrote:

I need some help with this.  I have installed email-spec (courtesy of
BMabey) and I have configure things thusly:

  Scenario: E-Mail Exchange Rates to notify parties
Given a currency exchange feed from the Bank of Canada
When the currency exchange retrieval script runs
Then I should receive an email

Then /should receive (an|\d+) e-?mails?/ do |amount|
  amount = 1 if amount == an
  unread_emails_for(current_email_address).size.should == amount.to_i
end


../environments/test.rb
# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.gem 'bmabey-email_spec', :lib = 'email_spec'


class MailerPublic  ActionMailer::Base
  def forex_daily_notice(address,rates)
rates_effective = Date.today.to_s(:db)
recipients  address.to_a
fromforexserv...@harte-lyne.ca
reply_tosupp...@harte-lyne.ca
subject #{rates_effective} - Foreign Exchange Rates Notice
body:rates_effective = rates_effective, :rates = rates
  end
end


./views/mailer_public/forex_daily_notice.text.plain.erb
Canada Customs foreign currency exchange rates for
currency conversion of shipments made on %...@rates_effective%

When I run this

./bin/script.rb
...
# Format and email the results.
if fx_hash_array
  puts got an array
  send_to = 'test_em...@example.com'
  MailerPublic.deliver_forex_daily_notice!(send_to,fx_hash_array)
  puts ActionMailer::Base.deliveries.length
  ActionMailer::Base.deliveries.each { |m| puts m }
end

Then I see this:

got an array
0

This is my first attempt at using ActionMailer so no doubt I have
overlooked something basic.  Can anyone tell me what it is?
  



Looks right to me.  To be honest though I have not used ActionMailer 
outside of Rails (where it just works out of the box).  I don't see 
anything wrong with the approach you are taking.  Maybe the rails 
mailing list could provide better advice.   Sorry, I couldn't be of any 
help.


-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Problems running features with Textmate Cucumber bundle

2009-04-26 Thread Ben Mabey

Rick DeNatale wrote:

I finally plunked down for the beta RSpec bundle and I'm working
through the initial example.  Although I'm a fairly experienced RSpec
user, I'm stlll learning new tricks.

Anyway,  I'm going though the mastermind example, and everything is
going well, except that I decided to also try out the Textmate bundle
for Cucumber.  I decided to use Ben Mabey's fork on github since it
seems to be the most evolved.

When I try to run a feature with cmd-R, instead of actually running I
see something like:

Running: cucumber
/Users/rick/mastermind/features/codebreaker_starts_game.feature --format=html
false

Cucumber runs fine from bash.

Am I missing some setup?

  
Hmm.. that is odd. What version of Cucumber are you using?  When you run 
that exact command from the shell does it output the HTML report?


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] BDD for C#?

2009-04-25 Thread Ben Mabey

Brandon Olivares wrote:

Hi,

I know this is slightly off topic, but I'm having trouble finding something,
and wondered if anyone here had experience with any BDD frameworks for C#.

I found NBehave (http://www.codeplex.com/NBehave), but it seems a little out
of date (last release says 2007 I think). I also found this post
(http://www.lostechies.com/blogs/joe_ocampo/archive/2008/02/26/updates-to-nb
ehave.aspx) which has a different syntax, but can't find what has happened
to it since that post. Also, I really hate that the methods use underscores,
though I don't know if that's their convention, or a requirement.

Does anyone else here use C#? What do you use for testing / specs?

Thanks,
Brandon


  
I haven't used C# for years, so I don't have any experience with BDD 
frameworks in it but you might want to check out MSpec:


http://github.com/machine/machine.specifications/tree/master

http://codebetter.com/blogs/aaron.jensen/archive/2008/05/08/introducing-machine-specifications-or-mspec-for-short.aspx

You may also want to post your question to the BDD google group:

http://groups.google.com/group/behaviordrivendevelopment?hl=en

HTH,
Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber - step negating another expecting step

2009-04-23 Thread Ben Mabey

David Chelimsky wrote:

On Thu, Apr 16, 2009 at 10:35 AM, Matt Wynne m...@mattwynne.net wrote:
  

On 16 Apr 2009, at 14:06, Joaquin Rivera Padron wrote:



thanks matt,
yes, the regexp in the step matcher is a good one to dry it up

So I end up with this one:

Then /^I (should|should not) see the people search form$/ do |maybe|
 people_search_form_should_exist maybe == should
end

and the method:

def people_search_form_should_exist it_should_exist
 _not = _not unless it_should_exist

 response.send should#{_not}.to_sym, have_tag('form#frmSearch')
end

only because I find it easier to read (when I don't need to jump to the
method), but yours maybe faster (shorter it is), I could come back to it
later and benchmark both
  

If you don't mind using the #send (I was trying to help you get rid of it)
then just do this:

Then /^I (should|should not) see the people search form$/ do |maybe|
 response.send maybe.underscore.to_sym, have_tag('form#frmSearch')
end



I'm definitely on the clarity trumps DRY side of the fence here. But
that doesn't deny that there is a problem to solve. This solution gets
close but is still takes me some extra time to grok. What extracting
that to a method like this:

Then /^I (should|should not) see the people search form$/ do
|should_or_should_not|
  expect_that(response, should_or_should_not, have_tag('form#frmSearch'))
end

def expect_that(target, should_or_should_not, matcher)
  target.send should_or_should_not.underscore.to_sym, matcher
end

I definitely don't see this in Cucumber, BTW as should and should
not are not the only way to express positive and negative
expectations even in English, let alone other languages that might not
deal w/ negation in such clean and consistent ways.

And it's not the least number of characters you can type. But it's
grok-able IMO. And DRY. And cute, to boot.

Of course, if anybody can come up with one word other than maybe
(damn you Ben Mabey for f'ing up my ability to type that word) to
  


LOL... I seem to have that effect on people. :)  But, think how I feel.  
Do you know how many witty people I have met who tell some maybe 
joke and think they are the first person to ever make it?  Well, I can 
tell you that it does, in fact, get very old. :)

express should_or_should_not more succinctly, that might help reduce
the typing. Maybe doesn't work for me because it implies lack of
precision rather than choice (to me).
  


Back on topic...  I like this proposal the best.  Having the  
should_or_should_not makes it very clear what is happening.  To reduce 
typing I suppose you could call it expectation in the step 
definition... and you could possibly even abbrevaite that more.  But I 
wold probably stick with the more verbose should_or_should_not.  I 
also agree that this is something that shouldn't be part of Cucumber 
itself but I'll probably play around with it in my own projects.


-Ben *Mabey*




Don't know how helpful this is, but it's fun to explore.

David

  


thanks again,
joaquin
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users



___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
  


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] Tables

2009-04-21 Thread Ben Mabey

aslak hellesoy wrote:



On Tue, Apr 21, 2009 at 10:20 PM, Joseph Wilk j...@josephwilk.net 
mailto:j...@josephwilk.net wrote:


On Tue, Apr 21, 2009 at 7:32 PM, Jonathan Linowes
jonat...@parkerhill.com mailto:jonat...@parkerhill.com wrote:

 On Apr 21, 2009, at 1:57 PM, Joseph Wilk wrote:

 What you really want is an examples table that is embedded in a
step
 (different from a step table, maybe by keyword?) that causes
the step to be
 run multiple times for each of the values. So rather than using
placeholders
 we embedded a Examples table in the step.


 like this?

Not quite, I was thinking of running the whole scenario for the
examples step table rather than just the step.

However I really like Ben's suggestion of a sub-table
(http://gist.github.com/99255).

I think it would be conceptually easier for a non-technical user to
grasp than my first suggestion which makes it a big win for me.


Thanks a lot for all the suggestions so far. I like Ben's subtable too.
In the example: I should be presented a menu with Meat Options I 
assume the step definition would be:


Then /I should be presented a menu with/ do |meat_hash|
  # meat_hash has the following value the 2nd time (Jewish):
  {'Pork'='N', 'Lamb'='Y', 'Veal'='Y'}
end

However, having the Meat Options as part of the step would be 
inconsistent with how the regexp matching is currently working.


Here is an alternative: http://gist.github.com/99376

The idea is that we add a new kind of multiline argument in addition 
to pystrings and tables: Hash. This is
done using the familiar  delimiters as a multiline argument. What's 
inside it has no significance other than documentation.
The keys of the hash would be the same as the Examples table header 
*minus* the columns that are referred in other steps.


In essence it achieves the same as Ben's, but relying on a convention 
(removing referenced columns) rather than introducing

a new, more complex table markup.

WDYT?


Interesting.. so your meat_hash was derived from the columns of the 
table that were not used previously in the scenario?  Meaning, that is 
why Religion was not part of your meat_hash.


That makes sense, and.. since the scenario outline is parsed before any 
of the examples are ran through that convention could be maintained no 
matter what order the delimiters appear in the scenario. (Just thinking 
out loud here...)


Yeah,  I like it. I also agree with Matt about meat_hash.  All this 
meat_hash talk is making me hungry...


However, what if people wanted multiple hashes?  Subtables would allow 
for this but a single hash solution would not.  FWIW, here is a very 
contrived exampled:


http://gist.github.com/99424

I agree that the sub-table is probably adding too much complexity, 
especially since we have a simpler alternative and no real use cases for 
it yet.  Basically, you can ignore that last gist, I was just 
experimenting with contrived use cases. :)



-Ben




Aslak
 



--
Joseph Wilk
http://blog.josephwilk.net


https://rspec.lighthouseapp.com/projects/16211/tickets/149-step-outline

 ___
 rspec-users mailing list
 rspec-users@rubyforge.org mailto:rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org mailto:rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users




___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] How to get stacktrace for extending Ruby in C

2009-04-21 Thread Ben Mabey

Newb Newb wrote:

Scott Taylor wrote:
  

Newb Newb wrote:


Hi

I extend ruby with C .

i get error like segmentation fault when i call my client.rb

how can i get the stacktrace ?
  
  

You can use gdb to get a stack trace, as was documented by Mauricio,
Jamis, and Why a while back.

Not sure what this has to do with rspec, though.

Scott



thanks for the reply..

I m running on  windows..

so is it possible to use gdb on windows..
  

http://hamsterrepublic.com/ohrrpgce/index.php/GDB_on_Windows.html

I'm sorry, but I couldn't resist...
http://tinyurl.com/dcz4b9

If I had more direct experience I would offer it. :)

-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] How can I pass an XML block as a parameter?

2009-04-14 Thread Ben Mabey


On Apr 14, 2009, at 5:39 PM, Wolfram Arnold wrote:


We're trying to verify XML REST API's and would like to write Cucumber
specs of the following type:

 Scenario: Create a phrase
   Given I have an authenticated session for user with login steve
   When I send a POST to /phrases with parameters: locale=ca and post
body
 ?xml version=1.0 encoding=UTF-8?
   phrase
   uuid060e985b-0307-4c8f-b43f-c16f0e45196d/uuid
   textFake Catalan Source/text
   source_languageca/source_language
   /phrase
   Then I get a 201 (created) status result
   And I a phrase object with UUID=060e985b-0307-4c8f-b43f- 
c16f0e45196d

exists on the server

In other words, we're trying to pass a multi-line value to the parser.


Have you tried the pystring syntax?

Given I want to have multiple lines

I can pass them
in with three quotes...



-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [Cucumber] How can I pass an XML block as a parameter?

2009-04-14 Thread Ben Mabey

Stephen Eley wrote:

On Tue, Apr 14, 2009 at 10:37 PM, Stephen Eley sfe...@gmail.com wrote:
  

Sorry if I'm asking dumb questions, but I was trying to look this up a
few weeks ago myself to represent some example Markdown data, and
eventually gave up.  This isn't documented anywhere that I could find.
 I've also never heard of pystring syntax -- I just tried to Google
that too, but all I got were references to Java libraries and no
simple syntax reference.



All right, never mind.  Having been given enough clues that the
feature exists and what it generally might look like, I prowled
through Cucumber's specs and examples until I got a clearer picture.
Then, to keep my 'There ain't no documentation!' whining privileges, I
went and added what I learned to the wiki:

http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments

I'd call it my minor good deed for the day, but really I was using it
to procrastinate on my podcasting work for another half hour, so
overall it was morally neutral.


  
lol.. Sorry for not explaining the syntax better... What you wrote on 
the wiki is great and doesn't really need further explanation by Ben 
Mabey or anyone else IMO. ;)


I'll go ahead and elaborate on it though.  Thanks for adding the page.

-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Cucumber - Recommended viewing.

2009-04-13 Thread Ben Mabey

aslak hellesoy wrote:



On Sun, Apr 12, 2009 at 5:35 PM, Ben Mabey b...@benmabey.com 
mailto:b...@benmabey.com wrote:


Matt Wynne wrote:


On 11 Apr 2009, at 01:07, James Byrne wrote:


http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html



Great job with the talk Ben, it's a really good intro to
Cucumber and I will be pointing anyone who asks towards it.

One question about the kitten-killing. I was surprised that
defining methods in your env / step_definition files adds
methods to *every instance* of Object. I thought it just added
those methods to the particular instance of Object that's used
to create the World.

Did I misunderstand the you in the talk, or misunderstand the
code in Cucumber?

Well, the step definitions themselves don't add themselves to
every instance.  The Given, When, and Then methods have actually
killed some kittens and already live on Object (sometimes it is
okay).  The step methods will register the passed in blocks to the
StepMother-- not onto Object.  So if that is what you are
referring to you are correct.

 
This isn't exactly how it works. The Given, When, Then methods (and a 
few others) are defined in the Cucumber::StepMother module. This 
module is extended by the Ruby top level object, which is a single 
instance. Object is not altered. Here is an interesting discussion 
about it: 
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/7b023b23385241c7?pli=1


Interesting.. I knew that the methods started out in 
Cucumber::StepMother but I thought they had to be added to every 
instance of Object to exhibit the behaviour that they do.  That makes 
even more sense now-- and it is a very nice technique to know about!  
Thanks for clearing up that misunderstanding.


-Ben
 
 



However, if you want to create a ruby helper method then you will
need to wrap it in a module to prevent to from being added to
every object instance.  In my example I had something like:

def login_as(user)
 visit '/login'
 fill_in 'Email', :with = user.email
 fill_in 'Password', :with = 'password'
 click_button
end

If you place that method in the top-level in either your env.rb or
any step files it is going to be living on Object since Cucumber
will load up these files as any other ruby file.  So you could
call #login_as on an Array or any other object!  Definitely not
what we want.  So, you need to wrap it in a module and use the
World hook to make the helper methods available only in your World
(which you get a new one for every scenario).  With the new World
syntax (as of 0.2.3 I believe) it would be:

module UserHelpers
 def login_as(user)
  visit '/login'
  fill_in 'Email', :with = user.email
  fill_in 'Password', :with = 'password'
  click_button
 end
end

World(UserHelpers)

I feel like I may of just repeated what I said in the
presentation... so you still may be just as confused. :/  Let me
know if that helps to clarify things or what part of it is confusing.

-Ben

___
rspec-users mailing list
rspec-users@rubyforge.org mailto:rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users




___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


  1   2   3   4   >