[rspec-users] Different description in custom RSpec::Matcher depending on output formater

2013-04-09 Thread Ervin Weber
Hello is it possible to make something like following:

RSpec::Matchers.define :be_json do |expected|
  match do |actual|
JSON.parse(actual) == expected
  end

  description do
if html? # to html formatter output this
   return JSON:\n#{JSON.pretty_generate(expected)}
else # for other formats condensed output
  return JSON:\n#{expected}
end
  end
end

I plan to use this running two formatters at same time  -f doc and -f
html at same time to produce pretty HTML file,  and relatively
condensed doc in console.

Big thanks, forward,
Ervin.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Simular to Include

2013-02-27 Thread Ervin Weber
Misunderstood examples.
Array1.collect{|s| s.split ('/').last}.should == array2 seems closer to
your intent.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Simular to Include

2013-02-27 Thread Ervin Weber
(Array1 - array2).should be_blank maybe?
On 28 Feb 2013 07:42, Mattias A. li...@ruby-forum.com wrote:

 Hi,

 I have array1 that contains several web address. Array2 contains the
 expected endings of array1 values. How can I control that arrays2 values
 is in array1?

 I have tried array1.should include array2, but it requires that array1
 and array2 is identical.


 array1 = [https:///page.html, https:///page1.html,
 https:///page3.html]

 array2 = [page.html, page2.html, page3.html, page4.html]

 A big thanks in advance!

 Regards
 Mattias

 --
 Posted via http://www.ruby-forum.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] what would be the best way to stub out an XHR request's response?

2012-09-26 Thread Ervin Weber
You could create some function (say window.GiveMeUrlForAjax) that
returns uri for ajax request, your test could then easily overwrite
that function before triggering event to perform ajax. Also you might
consider creating a function that returns data (in production it would
take url from GiveMeUrlForAjax and do real ajax) so you could
stub it in unit tests also.
In my opinion it is good to avoid all if test?  statements in
production code (you always can refactor them all into single config
file).

On Wed, Sep 26, 2012 at 7:16 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 If I have a javascript ajax request happening that fetches json data
 from a remote service, and I want to be running an integration test with
 rspec-- what would be the best way to stub out that service?

 The ideas that I've come up is:

 manually add a route + open up application controller from within my
 spec and dynamically create an action that returns mock json...  Then
 make my .js a .js.erb file, and do something like:

 $.ajax({ url: %= Rails.env.test? ?
 /my_added_route_that_hits_the_controller_method_that_returns_json :
 http://somewebservice.com/feed; % });

 Can anyone come up with any better solutions?

 Patrick J. Collins
 http://collinatorstudios.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