Module: Zebra::ShouldaSupport
- Defined in:
- lib/zebra/shoulda.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/zebra/shoulda.rb', line 3 def self.included(klass) klass.class_eval do attr_accessor :expects alias_method :build_without_expects, :build alias_method :build, :build_with_expects end end |
Instance Method Details
#build_with_expects ⇒ Object
36 37 38 39 |
# File 'lib/zebra/shoulda.rb', line 36 def build_with_expects (expects || []).each { |e| create_test_from_expect(&e) } build_without_expects end |
#create_test_from_expect(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/zebra/shoulda.rb', line 17 def create_test_from_expect(&block) test_name = expect_test_name(full_name, &block) if test_unit_class.instance_methods.include?(test_name.to_s) warn " * WARNING: '#{test_name}' is already defined" end context = self test_unit_class.send(:define_method, test_name) do begin context.run_parent_setup_blocks(self) context.run_current_setup_blocks(self) block.bind(self).call ensure context.run_all_teardown_blocks(self) end end end |
#expect(&block) ⇒ Object
12 13 14 15 |
# File 'lib/zebra/shoulda.rb', line 12 def expect(&block) self.expects ||= [] self.expects << block end |