Archive for the ‘Introduction’ Category
BDD(behavior driven development) with easyb
hi,
just wondering is there anyone who started using easyb?
which is behavior driven development framework. if you are not familiar with BDD here is my explanation.
as you heard and practicing TDD (test driven development), (if you follow test first approach) you keep your specification up front through test case.
for example -
public void testShouldCreateAnUserWhenItHasValidData() {…}
as you can see, you are actually writing test case for behavior(specification) for your expected code.
and based on that test case you are implemented your logic in code. this how TDD works. for more explanation google IT
in BDD, this process is more simplified, for example if you look at my previous example -
public void testShouldCreateAnUserWhenItHasValidData() {…}
you can find, i have written one scenario when user object has valid data.
same test can be in different scenarios such as, when user object has no valid data. or the caller is not authorized and so on.
so to make such thing clear in java code, it requires code like the following. ie.
public void testShouldCreateAnUserWhenItHasNoValidData();
public void testShouldCreateAnUserWhenItHasValidDataButCallerIsNotPermitted();
public void testShouldCreateAnUserWhenItHasValidDataButCallerIsPermitted();
here how BDD is proposing a new approach of making this thing more fluent through a simplified test framework.
like JUnit, easyb is also another test framework, where you are writing your test context, and behavior in groovy code.
actullay the beauty is test scenario are written following the user story convention
which is similar with the ideal convention
“as an Author
i want to write book
so that user can understand me”.
you can also generate user story from the groovy code which you can’t do with JUnit.
so you don’t need to maintain separate document for maintaing user stories.
so when you are preparing user story and you can use easyb and groovy to format your user story rather than using ms word, excel or notepad text file ![]()
ie.
import com.somewherein.bdd.UserServiceImpl
import com.somewherein.bdd.Userscenario “create a new user with valid data”, {
given “an user with the valid data”, {
user = new User()
userService = new UserServiceImpl()
state = false
}
when “creating a new user”, {
state = userService.createUser(user)
}
then “returned state should be true”, {
state.shouldBe true
}
and “newly created user should be found”, {
userService.exists(user)
}
}
when i run this test it says -
Scenarios run: 1, Failures: 0, Pending: 0, Time Elapsed: 0.649 sec1 behavior run with no failures
so if i ask for generating the user story – it generate the following text
scenario create a new user with valid data
given an user with the valid data
when creating a new user
then returned state should be true
then newly created user should be found
this type of practice is very common in ruby on rails based development.
in ruby we have several options, but RSpec is the early comer who showed how cool it could be.
anyway, this is something you should work try EiD vacation, happy test first development.
here is an article from javalobby
Is easyb Easy? | Javalobby
you can use it with spring framework, here is the example -
best wishes,
debugging rails internal query execution
while we were working with somewhere in… ads project we came up with some debugging and performance mesuring tool, here in my post i will describe how you can use it for yourself.
query debugging –

query debugging tool logs every executed query from active record and keep them in memory and using assisting template code it display all executed query from the active page.
also it executes query with mysql “explain” keyword. so on the same window you can see mysql query execution plan.
it helped us to track down queries which were not hitting the right index.
this is very simple trick – go through the code below -
module DebugUtil
class QueryDebug
@@QUERIES = {}
def self.add(p_query, p_report)
@@QUERIES[p_query] = p_report
enddef self.queries
q = @@QUERIES
clean
return q
enddef self.clean
@@QUERIES = {}
end
end
endQueryDebug class keeps all executed query and their explained resultset in to the static array. so later in template QueryDebug::queries is invoked to get all executed query for the current page.
here is how we trap the query execution from active record -
if defined?(QUERY_DEBUG_ENABLED) && QUERY_DEBUG_ENABLED
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
alias __existing_execute_method executedef execute(sql, name = nil)
if sql.match(/^SELECT/i)
report = []
@connection.query(“explain #{sql}”).each do |row|
report < < row
end
DebugUtil::QueryDebug.add(sql, report)
end
__existing_execute_method(sql, name)
end
endObject.class_eval do
def raise_during_query_debug
raise DebugUtil::QueryDebug::queries.inspect
end
end
endyou can see we have used “QUERY_DEBUG_ENABLED” constant to ensure whether this is enabled by intention.
now see how we are rendering on our template.
query debug
checked < %= row.join(“ “) % >
we put this code in common layout. so it renders on every page. thats all
builder pattern with fluent interface just an example while i was doing by routine work :)
today while i was working with one of my projects, i was wondering how this came up with a bit more fluent with my credential object.
just i can’t resists myself to share this code with every one.
assertNotNull(mProfileManager.authenticate(
Credential.Builder
.aNew().userName(userName).password(password).build()));
rails plugin symlinked broken on 1.2.5, fixed from 2.0
i was trying to build a rails plugin. my project was in different directory so i symlinked the directory under “vendor/plugins/..”. but i couldn’t find it working.
so after passing few times, i could successfully run my plugin under rails 2.0-RC2. so later i compared lookup.rb file from the 1.5 and 2.0-RC2 release.
the defecting code was the following lines – (1.5)
def use_component_sources!
# ….
sources < < PathSource.new(:lib, “#{::RAILS_ROOT}/lib/generators”)
sources << PathSource.new(:vendor, “#{::RAILS_ROOT}/vendor/generators”)
sources << PathSource.new(:plugins, “#{::RAILS_ROOT}/vendor/plugins/**/generators”)
# ….
end
the fixed version – (2.0-RC2)
def use_component_sources!
# …sources < < PathSource.new(:lib, “#{::RAILS_ROOT}/lib/generators”)
sources << PathSource.new(:vendor, “#{::RAILS_ROOT}/vendor/generators”)
sources << PathSource.new(:plugins, “#{::RAILS_ROOT}/vendor/plugins/*/**/generators”)
sources << PathSource.new(:plugins, “#{::RAILS_ROOT}/vendor/plugins/*/**/rails_generators”)
end
# …
end
i also checked out rails bug tracker i found a bug was pointed to this issue and apparently which was fixed on the following change set.
http://dev.rubyonrails.org/changeset/6101
on your active record model define has_many with dependent models.
i was refactoring our Item model, where we have 3 has_many with 3 mapping models.
as we are not using InnoDB based foreign key constraint, we were searching some sort of reliable solution,
which will take pressure in application layer instead of leaving it to the database.
so later we introduced “:dependent” with has_may relation. here is our top of Item model.
has_many :category_mappings, :dependent => :destroy
has_many :categories, :through => :category_mappings
has_many :property_values, :dependent => :destroy
has_many :properties, :through => :property_value
has_many :item_location_mappings, :dependent => :destroy
has_many :locations, :through => :item_location_mappings
our “dependent” flagship is destroying all related items in the item destroy process which has introduced
our flexibility and reduced a lot of code to manage such stuff in a DRY(ied) manner.
so the following unit test worked fine for us.

some bad side,
dependent delete each and every item one by one, which is big issue when you have a big chunk of dependent data.
but that is not suppose to be common in every context. we have no problem with this issue.
best of luck!
“work for fun”
attributes: rails reserved variable :(
yesterday, i had a pretty rough working day, i was stucked (along with my team) with some simple joining. we had the following models -
Attribute
———–
class Attribute < AR:B
belongs_to :category
end
class AttributeValue < AR:B
belongs_to :item
belongs_to :attribute
end
class Item :attribute_values
end
rails wasn’t giving much better error message, instead it was saying, “invalid type, String to Integer..”, so far i understood ActiveRecord stuff was trying to cast a string to integer.
we even didn’t know which field was doing this stupidity and so on…
so later we dug down to the rails scripts, we added few debug messages. we found “[]” was invoked to set “id” string value.
anyway, after digging more into to this issue, today i gave another try after 7 hours of nice sleep. it was about rails reserve words.
though i heard something from the rails community, but i was expecting some message or errors which explain this issue.
anyway, i always like fail first approach. if something is not possible it should fail first. at least it should return a meaningful exception.
i believe Active Record should be patched with more clear warning or exception, if any reserved word is used for model or controller or others it should let us inform
.
JETTY RUNNER version 0.2
those who doesn’t know about JETTY RUNNER:
JETTY RUNNER is a standalone swing based application which is used to bundle java ee based application along with jetty container. it comes with simple web app configuration xml file and global properties manager through a simple properties file.
actually i have been using this project for my own development solution, so i belief this project will become a great strengthen feature gradually.
JETTY RUNNER is now running on max OSX, i have removed system try support in new tag v-0.2, soon i will release *.dmg package for mac osx. here are few screen snaps -

figure – 1: server console main window

figure – 2: global properties editor
change logs -
1. removed system tray support
2. removed default jmx configuration
3. added “start.sh” to launch JETTY RUNNER on *nix based platform where ruby script is installed.
here are few screen snaps, which i have taken from the newly added ruby script! -

figure – 3: newly added jetty runner on ruby

figure – 4: newly added jetty runner implementation in ruby
this script really great
, at least i like it
Just bang, a new group, Rails artist, Only Ruby on Rails Artist here
these message convey the basic purpose of the rails_artist group-
Those who belief on themselves, those who believes they are passionate about the rails stuff in ruby way on rails, i belief this gonna create a new open space for them to share their nut and bolts.
from now on let’s change your title from developer, software engineer or architect to an ARTIST
![]()
welcome, dear artist.
here is the group url -
IntelliJ IDEA and ruby plugin
i belief, i should share this story, once i heard about apatana (eclipse based) ruby IDE i gave it a try without being late, later i heard Net beans got ruby supported, again i wasn’t late and gave it a try.
as you know, i am java developer, always like java stuff everywhere (if possible). anyway, later i returned to my favorite IDE IntelliJ idea.
my personal judgement in terms of usable and flexibility i must say, intelliJ idea with ruby plugin just rocks!!
currently i am developing a active record kind of things where i am using java based repository model in back end and my restful web service clients are developed on ruby.
i am pleased with intelliJ idea, as because the ruby plugin is too friendly, though i faced lot of internal code hints related problem, but i could see those problems were fixed on new release.
here is the ruby plugin details page
It seems LinkedIn moved on tomcat !
after a long while i got myself on linked in site, as i got “Server spy” installed on my firefox browser, so i was getting the server name from the browser status menu.
anyway, today i found something different, actually “Server spy” said, linked in is using “Apache-Coyote/1.1″, as far i can remind, linked in was using sun application server previously.
i think it is really interesting, what led linked in to move over tomcat backed or tomcat based servlet container instead of sun application server?
anyway, if i find any info i would love to feed my blog




