spec/presenter_spec.rb in curly-templates-1.0.1 vs spec/presenter_spec.rb in curly-templates-2.0.0.beta1
- old
+ new
@@ -21,30 +21,33 @@
class FancyCircusPresenter < CircusPresenter
presents :champagne
end
+ class CircusPresenter::MonkeyPresenter < Curly::Presenter
+ end
+
describe "#initialize" do
let(:context) { double("context") }
- it "sets the presented parameters as instance variables" do
+ it "sets the presented identifiers as instance variables" do
presenter = CircusPresenter.new(context,
midget: "Meek Harolson",
clown: "Bubbles"
)
presenter.midget.should == "Meek Harolson"
presenter.clown.should == "Bubbles"
end
- it "raises an exception if a required parameter is not specified" do
+ it "raises an exception if a required identifier is not specified" do
expect {
FancyCircusPresenter.new(context, {})
- }.to raise_exception(ArgumentError, "required parameter `champagne` missing")
+ }.to raise_exception(ArgumentError, "required identifier `champagne` missing")
end
- it "allows specifying default values for parameters" do
+ it "allows specifying default values for identifiers" do
# Make sure subclasses can change default values.
french_presenter = FrenchCircusPresenter.new(context)
french_presenter.elephant.should == "Babar"
# The subclass shouldn't change the superclass' defaults, though.
@@ -73,26 +76,40 @@
Curly::Presenter.presenter_for_path("foo/bar")
end.to raise_error(NameError)
end
end
- describe ".available_methods" do
+ describe ".presenter_for_name" do
+ it "returns the presenter class for the given name" do
+ CircusPresenter.presenter_for_name("monkey").should == CircusPresenter::MonkeyPresenter
+ end
+
+ it "looks in the namespace" do
+ CircusPresenter.presenter_for_name("french_circus").should == FrenchCircusPresenter
+ end
+
+ it "returns NameError if the presenter class doesn't exist" do
+ expect { CircusPresenter.presenter_for_name("clown") }.to raise_exception(NameError)
+ end
+ end
+
+ describe ".available_components" do
it "includes the methods on the presenter" do
- CircusPresenter.available_methods.should include(:midget)
+ CircusPresenter.available_components.should include("midget")
end
it "does not include methods on the Curly::Presenter base class" do
- CircusPresenter.available_methods.should_not include(:cache_key)
+ CircusPresenter.available_components.should_not include("cache_key")
end
end
- describe ".method_available?" do
+ describe ".component_available?" do
it "returns true if the method is available" do
- CircusPresenter.method_available?(:midget).should be_true
+ CircusPresenter.component_available?("midget").should == true
end
it "returns false if the method is not available" do
- CircusPresenter.method_available?(:bear).should be_false
+ CircusPresenter.component_available?("bear").should == false
end
end
describe ".version" do
it "sets the version of the presenter" do