Skip to content

Commit

Permalink
Renamed Term.convert to Term.encode
Browse files Browse the repository at this point in the history
  • Loading branch information
paukul committed Mar 17, 2010
1 parent e590ca9 commit 72e3370
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.o
*.so
*.bundle
Makefile
*.log
Expand Down
4 changes: 2 additions & 2 deletions src/term.c
Expand Up @@ -81,7 +81,7 @@ VALUE rb_value_from_binary(INTRUDER_TERM *iterm){
return Qnil;
}

VALUE intruder_term_convert(VALUE self, VALUE ruby_object){
VALUE intruder_term_encode(VALUE self, VALUE ruby_object){
VALUE ret = Qnil;

ETERM *eterm;
Expand All @@ -108,5 +108,5 @@ void Init_intruder_term(){

/* instance methods */
rb_define_method(IntruderTerm, "to_s", intruder_term_to_s, 0);
rb_define_singleton_method(IntruderTerm, "convert", intruder_term_convert, 1);
rb_define_singleton_method(IntruderTerm, "encode", intruder_term_encode, 1);
}
2 changes: 1 addition & 1 deletion src/term.h
Expand Up @@ -38,7 +38,7 @@ void Init_intruder_term();

/* instance methods */
VALUE intruder_term_to_s(VALUE self);
VALUE intruder_term_convert(VALUE self, VALUE ruby_object);
VALUE intruder_term_encode(VALUE self, VALUE ruby_object);

void free_intruder_term(void *term);
INTRUDER_TERM *new_intruder_term();
Expand Down
2 changes: 1 addition & 1 deletion test.rb
Expand Up @@ -7,7 +7,7 @@
puts "--- rabbit call ---\n"
n.connect("rabbit@#{hostname}")
m = n.mod('rabbit')
ret = m.status(Intruder::Term.convert([]))
ret = m.status(Intruder::Term.encode([]))
puts ret.to_s
puts ret.class

Expand Down
16 changes: 11 additions & 5 deletions test3.rb
Expand Up @@ -8,20 +8,26 @@
MiniTest::Unit.autorun

describe Intruder::Term do
describe ".convert" do
describe ".encode" do
it "should create atoms for symbols" do
assert_instance_of Atom, Term.convert(:a)
assert_instance_of Atom, Term.encode(:a)
end

it "should create empty lists for empty arrays" do
list = Term.convert([])
list = Term.encode([])
assert_instance_of List, list
assert_equal 0, list.size
end

it "should raise an exception for datatypes that can't be converted" do
it "should create lists with atom members for arrays with symbols" do
list = Term.encode([:a])
assert_instance_of List, list
assert_isntance_of Atom, list[0]
end

it "should raise an exception for datatypes that can't be encodeed" do
assert_raises Intruder::Error do
Term.convert({:a => 1})
Term.encode({:a => 1})
end
end
end
Expand Down

0 comments on commit 72e3370

Please sign in to comment.