spec/jsonr_spec.rb in jsonr-0.0.2 vs spec/jsonr_spec.rb in jsonr-0.1.0

- old
+ new

@@ -1,7 +1,97 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -describe "Jsonr" do - it "fails" do - fail "hey buddy, you should probably rename this file and start specing for real" +describe "Jsonr::Generator" do + + context "an empty generator instance" do + + it "converts to empty json object" do + generator = Jsonr::Generator.new + generator.to_s.should == '{}' + end + end + + context "#redirect_to" do + + it "converts to json object with redirect_to key" do + generator = Jsonr::Generator.new do |page| + page.redirect_to '/new/url' + end + + generator.to_s.should == %Q|{"redirect_to":"/new/url"}| + end + + end + + context "#flash" do + + it "converts to json object with flash key" do + generator = Jsonr::Generator.new do |page| + page.flash :notice, "it's done!" + end + + generator.to_s.should == %Q|{"flash":{"notice":"it's done!"}}| + end + + it "converts all flashes" do + generator = Jsonr::Generator.new do |page| + page.flash :notice, "it's done!" + page.flash :error, "no it's not!" + end + + generator.to_s.should == %Q|{"flash":{"notice":"it's done!","error":"no it's not!"}}| + end + + end + + %w(hide show toggle remove).each do |cmd| + + context "##{cmd}" do + + it "convert to json object with hide key" do + generator = Jsonr::Generator.new do |page| + page.send cmd, '#selector1' + end + + generator.to_s.should == %Q|{"#{cmd}":["#selector1"]}| + end + + it "convert all given selectors" do + generator = Jsonr::Generator.new do |page| + page.send cmd, '#selector1', '.selector2' + end + + generator.to_s.should == %Q|{"#{cmd}":["#selector1",".selector2"]}| + end + + it "convert all given selectors when called more times" do + generator = Jsonr::Generator.new do |page| + page.send cmd, '#selector1' + page.send cmd, '.selector2' + end + + generator.to_s.should == %Q|{"#{cmd}":["#selector1",".selector2"]}| + end + + end + + end + + + %w(replace append prepend replace_with insert_before).each do |cmd| + + context "##{cmd}" do + + it "convert to json object with #{cmd} key" do + generator = Jsonr::Generator.new do |page| + page.send(cmd, "#selector1", "content") + end + + generator.to_s.should == %Q|{"#{cmd}":{"#selector1":"content"}}| + end + + end + + end + end