Skip to content

Commit

Permalink
attr_* are automatically not marked as tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 3, 2010
1 parent ef676f5 commit 1aa9eab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/thor/base.rb
Expand Up @@ -97,6 +97,18 @@ def register_klass_file(klass) #:nodoc:
module ClassMethods
attr_accessor :debugging

def attr_reader(*) #:nodoc:
no_tasks { super }
end

def attr_writer(*) #:nodoc:
no_tasks { super }
end

def attr_accessor(*) #:nodoc:
no_tasks { super }
end

# Adds an argument to the class and creates an attr_accessor for it.
#
# Arguments are different from options in several aspects. The first one
Expand Down
15 changes: 15 additions & 0 deletions spec/base_spec.rb
Expand Up @@ -233,4 +233,19 @@ def hello
}.must raise_error(Thor::UndefinedTaskError, /the 'what' task of MyScript is private/)
end
end

describe "attr_*" do
it "should not add attr_reader as a task" do
capture(:stderr){ MyScript.start(["another_attribute"]) }.must =~ /could not find/
end

it "should not add attr_writer as a task" do
capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }.must =~ /could not find/
end

it "should not add attr_accessor as a task" do
capture(:stderr){ MyScript.start(["some_attribute"]) }.must =~ /could not find/
capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }.must =~ /could not find/
end
end
end
4 changes: 4 additions & 0 deletions spec/fixtures/script.thor
@@ -1,4 +1,8 @@
class MyScript < Thor
attr_accessor :some_attribute
attr_writer :another_attribute
attr_reader :another_attribute

group :script
default_task :example_default_task

Expand Down

0 comments on commit 1aa9eab

Please sign in to comment.