Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a way to load stuff into world #166

Merged
merged 1 commit into from
Jan 23, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.*;

public class JRubyBackend implements Backend {
private static final String DSL = "/cucumber/runtime/jruby/dsl.rb";
Expand All @@ -27,6 +24,7 @@ public class JRubyBackend implements Backend {
private Glue glue;
private ResourceLoader resourceLoader;
private UnreportedStepExecutor unreportedStepExecutor;
private final Set<JRubyWorldBlock> worldBlocks = new HashSet<JRubyWorldBlock>();

public JRubyBackend(ResourceLoader resourceLoader) throws UnsupportedEncodingException {
this.resourceLoader = resourceLoader;
Expand Down Expand Up @@ -68,6 +66,10 @@ public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
@Override
public void buildWorld() {
jruby.put("$world", new Object());

for (JRubyWorldBlock block : worldBlocks) {
block.execute();
}
}

private void runScriptlet(Resource resource) {
Expand Down Expand Up @@ -113,6 +115,6 @@ public void addAfterHook(RubyObject body) {
}

public void addWorldBlock(RubyObject body) {
new JRubyWorldBlock(body).execute();
worldBlocks.add(new JRubyWorldBlock(body));
}
}