Re: [rspec-users] Faking Files, Data, Git interractions with mocks/stubs/fixtures

2011-04-21 Thread Matt Wynne

On 19 Apr 2011, at 19:24, Josh N. wrote:

> I'm new to ruby and just learning cucumber and rspec. I have some
> examples(tests) that need to fake a directory structure and file
> grouping, fake a properly formatted json file and fake a ruby-git
> interraction (git.fetch, git.merge).
> 
> I've been reading about mocks and stubs but still feeling a little in
> the dark.
> 
> Given some example tests like the following
> 
> describe "#update_repo" do
>   it "should update the repository without errors" do
>git = double('git')
># How do I mock this so that the Git object is "faked" and the
> calls to fetch/merge don't cause an error without actually talking to a
> remote repo
>lambda { @app.update_repo git }.should_not raise_error
>   end
> end
> 
> describe "#check_json" do
>   it "should check that the har files are valid json if they exist" do
> # In the real context @app.files contains a list of har json
> files
> # How do I mock the json files on the file system
> test_contents = @app.organize_test_contents @app.files
> # Can I mock test_contents or use a fixture?
> result = @app.check_json test_contents
> result.should =~ /JSON Valid/
>   end
> end
> 
> What are some recommended ways for faking data, faking file systems,
> faking network interractions

Quick answer:

One well-trodden path is to use the adapter pattern to isolate the behaviour 
that actually interacts with the external file / network system behind an 
interface. I'd recommend Steve Freeman and Nat Pryce's book "Growing Object 
Oriented Software, Guided by Tests" (GOOS) where they talk about this in 
detail, as well as many other very useful testing techniques. The examples are 
in java, but the design principles apply equally to Ruby code.

> 
> -- 
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

cheers,
Matt

m...@mattwynne.net
07974 430184

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


[rspec-users] Routing assertions

2011-04-21 Thread siva
Hi

Thanks for help me out

 I have two routes :
   match 'admin/categories' => 'admin#categories', :as =>
'admin_category'
   match 'admin/categories/:sub_category' => 'admin#categories'

In rspec

--
  For first route

assert_routing({:path => "admin/categories"}, {:controller =>
'admin', :action => 'categories'})

  For second route

 assert_recognizes({:controller=>'admin', :action =>
'categories', :sub_category=>'2'}, 'admin/categories/2')
---
  For second route if i am using assert_routing  method I am getting
below error

Failure/Error: assert_routing({:path => "admin/categories/2"},
{:controller => 'admin', :action => 'categories', :sub_category =>
'2'})
 Test::Unit::AssertionFailedError:
   found extras <{:sub_category=>"2"}>, not <{}>

  Why assert_routing method is failing for second route? And also let
me know I which scenarios should I use assert_routing,
assert_generates and assert_recognizes?


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


Re: [rspec-users] Faking Files, Data, Git interractions with mocks/stubs/fixtures

2011-04-21 Thread andyl
I've been using the VCR gem lately and it is great.
Maybe this would be useful if you're fetching from git using http??
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users