Aucune description http://j1x-huginn.herokuapp.com

utils_spec.rb 1003B

12345678910111213141516171819202122232425262728
  1. require 'spec_helper'
  2. describe Utils do
  3. describe "#value_at" do
  4. it "returns the value at a JSON path" do
  5. Utils.value_at({ :foo => { :bar => :baz }}.to_json, "foo.bar").should == "baz"
  6. Utils.value_at({ :foo => { :bar => { :bing => 2 } }}, "foo.bar.bing").should == 2
  7. end
  8. it "returns nil when the path cannot be followed" do
  9. Utils.value_at({ :foo => { :bar => :baz }}, "foo.bing").should be_nil
  10. end
  11. it "does not eval" do
  12. lambda {
  13. Utils.value_at({ :foo => 2 }, "foo[?(@ > 1)]")
  14. }.should raise_error(RuntimeError, /Cannot use .*? eval/)
  15. end
  16. end
  17. describe "#values_at" do
  18. it "returns arrays of matching values" do
  19. Utils.values_at({ :foo => { :bar => :baz }}, "foo.bar").should == %w[baz]
  20. Utils.values_at({ :foo => [ { :bar => :baz }, { :bar => :bing } ]}, "foo[*].bar").should == %w[baz bing]
  21. Utils.values_at({ :foo => [ { :bar => :baz }, { :bar => :bing } ]}, "foo[*].bar").should == %w[baz bing]
  22. end
  23. end
  24. end